import datetime
print(datetime.datetime.now()) # 2016-05-17 15:46:40.784376 获取当前的日期和时间
print(datetime.datetime.now()+datetime.timedelta(days=10)) # 2016-05-27 15:47:45.702528 将当前的时间向后推迟10天
print(datetime.date.today()) # 2016-05-17 获取当前的日期
print(datetime.datetime.utcnow()) # 2016-05-17 08:23:41.150628 获取格林威治时间
print(datetime.datetime.now().timetuple()) # time.struct_time(tm_year=2016 ... tm_hour=16,...)获取当前一个包含当前时间的结构体
print(datetime.datetime.now().timestamp()) # 1463473711.057878 获取当前的时间戳
print((datetime.datetime.fromtimestamp(1463473711.057878))) # 2016-05-17 16:28:31.057878 将时间戳转换成日期和时间
print(datetime.datetime.strptime('2016-05-17 16:28:31','%Y-%m-%d %H:%M:%S')) #2016-05-17 16:28:31 str转换为datetime
print(datetime.datetime.now().strftime('%D, %m %d %H:%M')) #05/23/16, 05 23 10:10 datetime转换为str
python datetime 常用用法
最新推荐文章于 2022-08-27 11:03:07 发布