时间字符串格式转换为秒数

import time,datetime
 
#获取今日凌晨的时间
d = datetime.datetime.strptime(str(datetime.date.today()),"%Y-%m-%d")
time_sec_float = time.mktime(d.timetuple())
print time_sec_float
 
 
#三种不同格式字符串转秒数:

expire_time = "2015-11-5"      (不带具体时间的,默认按当日 00:00:00处理)

d = datetime.datetime.strptime(expire_time,"%Y-%m-%d")

time_sec_float = time.mktime(d.timetuple())

print time_sec_float

 
 

expire_time = "2015-11-05 00:00:00"

d = datetime.datetime.strptime(expire_time,"%Y-%m-%d %H:%M:%S")

time_sec_float = time.mktime(d.timetuple())

print time_sec_float

 
 

page_time="2015年11月06日"

d = datetime.datetime.strptime(page_time,"%Y年%m月%d日")

time_sec_float = time.mktime(d.timetuple())

print time_sec_float

 

posted @ 2017-04-05 14:47  光彩照人  阅读(3484)  评论(0编辑  收藏  举报