[英]AWS Glue job, Python script for datetime.today().strftime(%y/%m/%d) getting UTC date & time?
AWS Glue job, Python script for datetime.today().strftime(%y/%m/%d) getting UTC date & time NOT USA date & time. AWS Glue 作业,Python 脚本 datetime.today().strftime(%y/%m/%d) 获取 UTC 日期和时间而不是美国日期和时间。 Basically tomorrow date & time, if you run above function.基本上明天的日期和时间,如果你在 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:如果您希望UTC
中的当前时间具有给定格式%y/%m/%d
,则可以使用以下命令:
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:如果您希望当前时间位于不同的时区,可以使用pytz
lib,并执行以下操作:
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.由于美国有多个时区,select 是您想要的特定区域。 To list all the regions in pytz
, run the following:要列出pytz
中的所有区域,请运行以下命令:
>>> import pytz
>>> pytz.all_timezones
['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.