python-时间相关

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值