How to get python to display current time (eastern)

后端 未结 4 1173
挽巷
挽巷 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:40

    There is a much more intuitive way, of course:

    from datetime import datetime
    from pytz import timezone
    tz = timezone('EST')
    datetime.now(tz) 
    ## this returns a datetime object pointing to right now 
    ## according to the timezone info object handed in as the tz variable. 
    

    Alternatively you can define your own datetime object and pass in tz as tzinfo, as you can see below:

    datetime(2016, 3, 30, 11, 13, 24, tzinfo=tz)
    

提交回复
热议问题