firemail
标题:
python日期时间处理
[打印本页]
作者:
java
时间:
2018-3-21 13:58
标题:
python日期时间处理
# 获取当前时间
time_now = int(time.time())
# 转换成localtime
time_local = time.localtime(time_now)
dt = time.strftime("%a, %d %b %Y %H:%M:%S %Z", time_local) #'Wed, 21 Mar 2018 13:54:41 CST'
# 转换成新的时间格式(2016-05-09 18:59:20)
dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
# 带星期的显示格式 Wed Mar 21 12:10:03 2018
dt2 = time.ctime()
localtime = time.asctime(time.localtime(time.time()))
如何转成GMT时间
# 转成 HTTP1.1 中支持的 GMT 格式 与服务端时间相差8小时以外,将返回403。比如:Wed, 17 Feb 2012 15:31:56 GMT
dt = time.gmtime(time.time())
dtGMT = time.strftime("%a, %d %b %Y %H:%M:%S GMT", dt) #????? CST
欢迎光临 firemail (http://firemail.wang:8088/)
Powered by Discuz! X3