给自己放了几天假,过了过中秋。可以收心了,继续我的是事情,到我喜欢的地方了,常用的模块
- 时间模块time和datetime
所有的时间开始于:纪元时间1970年,也叫时间戳timestamp
time.time() #当前时间戳
time.strftime('%Y-%M-%D %X) #格式化的字符串时间
格式化字符串的时间格式:
1 %a Locale’s abbreviated weekday name. 2 %A Locale’s full weekday name. 3 %b Locale’s abbreviated month name. 4 %B Locale’s full month name. 5 %c Locale’s appropriate date and time representation. 6 %d Day of the month as a decimal number [01,31]. 7 %H Hour (24-hour clock) as a decimal number [00,23]. 8 %I Hour (12-hour clock) as a decimal number [01,12]. 9 %j Day of the year as a decimal number [001,366]. 10 %m Month as a decimal number [01,12]. 11 %M Minute as a decimal number [00,59]. 12 %p Locale’s equivalent of either AM or PM. (1) 13 %S Second as a decimal number [00,61]. (2) 14 %U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. (3) 15 %w Weekday as a decimal number [0(Sunday),6]. 16 %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (3) 17 %x Locale’s appropriate date representation. 18 %X Locale’s appropriate time representation. 19 %y Year without century as a decimal number [00,99]. 20 %Y Year with century as a decimal number. 21 %z Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59]. 22 %Z Time zone name (no characters if no time zone exists). 23 %% A literal '%' character.
time.ctime(time.time()) #'Fri Sep 28 17:51:22 2018' 相当于 time.asctime() #时间显示
日期:datetime.datetime.now()
datetime.date.fromtimestamp(time.time())