reference1
一些常识:
- GMC(Greenwich Mean Time)格林尼治标准时,现在已不再那么标准,故用UTC。
- UTC,世界标准时间,由于英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC。
不需要精确到秒的情况下,通常将GMT 和UTC 视作等同,但UTC 更加科学更加精确,它是以原子时为基础,在时刻上尽量接近世界时的一种时间计量系统。
Python中时间一般有3种形式:
- timestring,字符串形式的时间,type为str
datitime_obj.strftime()
time.strftime(formatstring, time_tp) localtimetuple, 即timetuple,为time的struct_time对象,返回9个int值
time.localtime() # 即可,localtime为当地的太阳时,各地不同。
time.gmttime() # 返回也是timetuple
time.strptime(‘timestring’, format) # 返回也是timetuple
datetime.datetime.timetuple(datetime.datetime.today()) # 返回也是timetuple
time.strptime(time_string, format_string)timestamp(即时间戳), seconds since Epoch
时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数
time.time() # 时间戳
time.mktime(time_tp)
另附格式化编码符号:
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale’s abbreviated weekday name.
%A Locale’s full weekday name.
%b Locale’s abbreviated month name.
%B Locale’s full month name.
%c Locale’s appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale’s equivalent of either AM or PM.