time类/datetime类

https://blog.csdn.net/Rozol/article/details/71307483

time.time()返回的是一个浮点数,单位为秒。但strftime处理的类型是time.struct_time,实际上是一个tuple

>>> import time

>>> print time.time()

1533097203.55

>>> ac =  time.localtime(time.time())

time.struct_time(tm_year=2018, tm_mon=8, tm_mday=1, tm_hour=12, tm_min=20, tm_sec=20, tm_wday=2, tm_yday=213, tm_isdst=0)

>>> time.strftime('%Y-%m',ac)

'2018-08'

 

import datatime

>>> datetime.datetime.today()

datetime.datetime(2018, 8, 1, 14, 3, 19, 675435)

>>> dl=datetime.datetime.today()

>>> dl

datetime.datetime(2018, 8, 1, 14, 3, 31, 39252)

>>> print dl

2018-08-01 14:03:31.039252

>>> datetime.datetime.today()

datetime.datetime(2018, 8, 1, 14, 3, 59, 669356)

>>> dy = dl.strftime('%y--%m')

>>> dy

'18--08'

>>> data = dl.date()

>>> print data

2018-08-01

>>> tim = dl.time()

>>> print tim

14:03:31.039252

print("现在是 {}年 {}月 {}日".format(data.year, data.month, data.day))

现在是 2018年 8月 1日

 kprq = kprq.strftime('%Y年%m月%d日')?

你可能感兴趣的:(学习笔记)