#导入日期模块
import time
print time.time() #获取当前时间
localtime = time.localtime(time.time()) #把字符型转成日期型
print localtime
print type(localtime) #<type 'time.struct_time'>
#把日期型按照一定格式转成str类型
time1 = time.strftime('%Y年%m月%d日', localtime) #第一个参数为格式化的样式,第二的参数为序列类型(argument must be 9-item sequence)
print time1
print type(time1)
#把字符串parse成为日期型
str1 = '2017年5月12日'
time2 = time.strptime(str1, "%Y年%m月%d日")
print time2
print type(time2) #<type 'time.struct_time'>
python基础------日期time
最新推荐文章于 2020-09-09 18:28:32 发布