How to get python to display current time (eastern)

后端 未结 4 1168
挽巷
挽巷 2021-02-07 07:17

How can I get Python to display the time in eastern?

I\'ve looked over the python documentation but it\'s pretty confusing. I\'m using Python 3.

Thanks.

4条回答
  •  隐瞒了意图╮
    2021-02-07 07:48

    If you need the entire timestamp:

    import datetime
    print (datetime.datetime.utcnow() - datetime.timedelta(hours=4))
    

    If you just need the date in YYYYmmdd format

    print (datetime.datetime.utcnow() - datetime.timedelta(hours=4)).strftime('%Y%m%d')
    

提交回复
热议问题