我是靠谱客的博主 靓丽盼望,这篇文章主要介绍python datetime的使用,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ' a test module ' __author__ = 'Zhang Shuai' import datetime t = datetime.datetime.now() #时间 如:2017-07-23 17:39:54.994200 print(t) #a 星期几的缩写 如:Sun print(t.strftime("%a")) #A 星期几的全拼 如:Sunday print(t.strftime("%A")) #b 月份的缩写 如:Jul print(t.strftime("%b")) #B 月份的全拼 如:July print(t.strftime("%B")) #c 时间 如:Sun Jul 23 17:39:54 2017 print(t.strftime("%c")) #D 如:07/23/17 print(t.strftime("%D")) #H 年 如:2017 print(t.strftime("%Y")) #m 月 如:07 print(t.strftime("%m")) #d 日 如:23 print(t.strftime("%d")) #H 时 如:17 print(t.strftime("%H")) #M 分 如:39 print(t.strftime("%M")) #S 秒 如:54 print(t.strftime("%S")) #格式化:2017-07-23 17-41-53 print(t.strftime("%Y-%m-%d %H-%M-%S")) #以整点为基础过了十周 如:70 days, 0:00:00 print(datetime.timedelta(weeks=10)) #以整点为基础过了十个小时 如:10:00:00 print(datetime.timedelta(hours=10)) #以整点为基础过了十分钟 如:0:10:00 print(datetime.timedelta(minutes=10)) #以整点为基础过了十秒 如:0:00:10 print(datetime.timedelta(seconds=10)) #我们可以以datetime.timedelta来计算时间 #如 当前时间的两小时十五分三秒的时间是多少 如:2017-07-23 15:34:46.591493 print(t-datetime.timedelta(hours=2,minutes=15,seconds=3))

最后

以上就是靓丽盼望最近收集整理的关于python datetime的使用的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部