• get current UTC datetime of Python


    API

    https://docs.python.org/3/library/datetime.html#datetime.datetime.now

    now接口获取本地时间, tz不带表示当地时区, 带上可以指定特定时区。

    utcnow获取世界协调时间

    classmethod datetime.now(tz=None)

    Return the current local date and time.

    If optional argument tz is None or not specified, this is like today(), but, if possible, supplies more precision than can be gotten from going through a time.time() timestamp (for example, this may be possible on platforms supplying the C gettimeofday() function).

    If tz is not None, it must be an instance of a tzinfo subclass, and the current date and time are converted to tz’s time zone.

    This function is preferred over today() and utcnow().

    classmethod datetime.utcnow()

    Return the current UTC date and time, with tzinfo None.

    This is like now(), but returns the current UTC date and time, as a naive datetime object. An aware current UTC datetime can be obtained by calling datetime.now(timezone.utc). See also now().

    Code

    https://stackoverflow.com/questions/15940280/how-to-get-utc-time-in-python

    法一

    from datetime import datetime
    datetime.utcnow()

    法二

    from datetime import datetime,timezone
    now_utc = datetime.now(timezone.utc)

    UTC

    https://www.cnblogs.com/champyin/p/12767852.html

    什么是UTC

    UTC(Coodinated Universal Time),协调世界时,又称世界统一时间、世界标准时间、国际协调时间。由于英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC。

    UTC 是现在全球通用的时间标准,全球各地都同意将各自的时间进行同步协调。UTC 时间是经过平均太阳时(以格林威治时间GMT为准)、地轴运动修正后的新时标以及以秒为单位的国际原子时所综合精算而成。

    在军事中,协调世界时会使用“Z”来表示。又由于Z在无线电联络中使用“Zulu”作代称,协调世界时也会被称为"Zulu time"。

    UTC 由两部分构成:

    • 原子时间(TAI, International Atomic Time):
      结合了全球400个所有的原子钟而得到的时间,它决定了我们每个人的钟表中,时间流动的速度。

    • 世界时间(UT, Universal Time):
      也称天文时间,或太阳时,他的依据是地球的自转,我们用它来确定多少原子时,对应于一个地球日的时间长度。

    UTC的历史

    1960年,国际无线电咨询委员会规范统一了 UTC 的概念,并在次年投入实际使用。

    “Coordinated Universal Time”这个名字则在1967年才被正式采纳。

    1967年以前, UTC被数次调整过,原因是要使用闰秒(leap second)来将 UTC 与地球自转时间进行统一。

    CST

    https://24timezones.com/shiqu/cst_china

    CST (中国标准时间) 是UTC+8时区的知名名称之一,比UTC(协调世界时)提前8个小时与UTC的时间偏差可写为+08:00.

    它被用作标准时间。

    出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    电商平台开发笔记5.nuxt项目中深度选择器解决el-input高度设置无效
    电商平台开发笔记4.css选择器之~波浪号使用
    电商平台开发笔记3.nuxt全局css的引入
    电商平台开发笔记2.Nuxt增加对less支持,解决This relative module was not found报错
    电商平台开发笔记1.Nuxt项目创建+Eslint代码保存自动格式化
    vue-cli 4.x 发布前的一些优化
    VueCli 4.x npm run build后主页空白的原因及解决方案
    VSCode 保存时自动ESlint格式化
    git 常用操作笔记
    VSCode下手动构建webpack项目
  • 原文地址:https://www.cnblogs.com/lightsong/p/14986262.html
Copyright © 2020-2023  润新知