How to get python to display current time (eastern)

Viewed 48829

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.

5 Answers

If for some reason you can't use pytz module and need simple solution then you can use

from datetime import datetime, timezone

datetime.now(timezone(timedelta(hours=-5), 'EST'))

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')
Related