首页 > 编程语言 > 详细

python3 5月26日 time模块常用时间转换

时间:2018-05-26 21:46:51      阅读:447      评论:0      收藏:0      [点我收藏+]

import time 

获取当前时间:

指定字符串格式:time.strftime("%Y-%m-%d %H:%M:%S")

当前时间戳:time.time()

当前时间元组格式:time.localtime()

字符串转时间格式

将时间字符串转按指定格式换为元组<class ‘time.struct_time‘>
time.strptime(“字符串”,format("%Y-%m-%dT%H:%M:%SZ"))

将时间格式转换为时间戳:
time.mktime(‘class ‘time.struct_time’格式的元组) #将时间格式元组转换为时间戳 <class ‘float‘>

time.gmtime(时间戳)将时间戳转换为UTC时间元组
time.localtime(时间戳)将时间戳转换为本地时区的时间元组

time.ctime(‘时间戳’)将时间戳转换为字符串(本地时间)    如Sat May 26 21:11:24 2018

time.asctime(时间元组)将时间格式元组转换为 特定固定格式字符串  如Sat May 26 21:11:24 2018

 

 

python3 5月26日 time模块常用时间转换

原文:https://www.cnblogs.com/zhangmingda/p/9094373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!