How to get the current time in Python

前端 未结 30 1812
滥情空心
滥情空心 2020-11-22 06:47

What is the module/method used to get the current time?

30条回答
  •  温柔的废话
    2020-11-22 07:38

    Try the arrow module from http://crsmithdev.com/arrow/:

    import arrow
    arrow.now()
    

    Or the UTC version:

    arrow.utcnow()
    

    To change its output, add .format():

    arrow.utcnow().format('YYYY-MM-DD HH:mm:ss ZZ')
    

    For a specific timezone:

    arrow.now('US/Pacific')
    

    An hour ago:

    arrow.utcnow().replace(hours=-1)
    

    Or if you want the gist.

    arrow.get('2013-05-11T21:23:58.970460+00:00').humanize()
    >>> '2 years ago'
    

提交回复
热议问题