码迷,mamicode.com
首页 > 编程语言 > 详细

python之 datatime 模块

时间:2018-01-23 23:21:45      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:格式化   天前   pos   data   当前时间   col   datetime   now()   格式   

datetime 和date 使用上类似

 1 import datetime
 2 print(datetime.datetime.today())#当前时间,到毫秒,datetime 类型 2018-01-23 21:55:43.756948
 3 now = datetime.datetime.now()#和today()一样,datetime 类型 
 4 print(now) #2018-01-23 21:55:43.756948
 5 print(now.year) #2018
 6 print(now.month) #1
 7 print(now.day) #23
 8 print(now.hour)#21
 9 print(now.minute)#55
10 print(now.second)#43
11 print(now.microsecond)#756947
12 print(datetime.datetime.today().strftime(%Y-%m-%d)) #2018-01-23,格式化时间
13 print(datetime.datetime.today() + datetime.timedelta(-3)) #3天前,datetime 类型 2018-01-20 21:55:43.756948
14 print(datetime.datetime.today() + datetime.timedelta(3)) #3天后,datetime 类型 2018-01-26 21:55:43.756948
15 print(datetime.date.today()) #2018-01-23 , <class ‘datetime.date‘>

 

python之 datatime 模块

标签:格式化   天前   pos   data   当前时间   col   datetime   now()   格式   

原文地址:https://www.cnblogs.com/nancyzhu/p/8338035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!