boss44 发表于 2017-4-29 10:47:39

python日期的几个经典使用

#!/usr/bin/python
# create:liubing
import time
import datetime
#毫秒转日期
def secondstoDate(d):
d=float(d)
return str(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(d)))
#日期转毫秒
def dateToSeconds(s):
d1=datetime.datetime.strptime(s,'%Y-%m-%d %H:%M:%S')
return time.mktime(time.strptime(d1.ctime(),"%a %b %d %H:%M:%S %Y"))

#d1=datetime.datetime.now() 获得当前时间
#d2=d1+datetime.timedelta(hours=-1) 获得前一个小时前的日期
页: [1]
查看完整版本: python日期的几个经典使用