AWS Glue job, Python script for datetime.today().strftime(%y/%m/%d) getting UTC date & time NOT USA date & time. Basically tomorrow date & time, if you run above function. How to get US date & time?
If you want the current time in UTC
with your given format %y/%m/%d
, you can use the following:
from datetime import datetime
time_now_utc = datetime.utcnow().strftime("%y/%m/%d")
If you want the current time at a different timezone, you can use pytz
lib, and do the following:
import pytz
tz = pytz.timezone('America/New_York')
time_now_ny = datetime.now(tz).strftime("%y/%m/%d")
Since USA has multiple timezones, select the specific region you want. To list all the regions in pytz
, run the following:
>>> import pytz
>>> pytz.all_timezones
['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ...]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.