python3中time模块与datetime模块的简单用法

 1 __author__ = "JentZhang"
 2 
 3 import time
 4 
 5 # Timestamp  时间戳
 6 print("Timestamp  时间戳:")
 7 print(time.time())
 8 print("#".center(50,"#"))
 9 
10 
11 # Structime  结构化时间
12 print("Structime  结构化时间:")
13 print(time.gmtime())
14 print(time.localtime())
15 print(time.struct_time)
16 print("#".center(50,"#"))
17 
18 # 格式化时间为能看得懂的格式
19 print("格式化时间为能看得懂的格式:")
20 print(time.strftime("%Y-%m-%d %X", time.localtime()))
21 print(time.strftime("%Y-%m-%d %X"))
22 print(time.strftime("%Y-%m-%d %H:%M:%S"))
23 print("#".center(50,"#"))
24 
25 import datetime
26 
27 # 计算3天前的当前时间
28 print("计算3天前的当前时间:")
29 time_str = (datetime.datetime.now() + datetime.timedelta(-3))
30 print(type(time_str))
31 print(time_str.strftime("%Y-%m-%d %H:%M:%S"))
32 # print(datetime.date)

 

posted on 2018-11-30 14:56  JentZhang  阅读(923)  评论(0编辑  收藏  举报