在我不知道时区区域名称的情况下,我需要在特定的timezone
中获取当前时间。基本上,我需要一种方法,我将传递时区的UTC
值,并期望返回为该区域的当前时间。我需要的方法应该是'
def get_current_time(utc_value):
#CODE
return current_time
print (get_current_time("+05:30"))`
而且我希望它能给我当前时间UTC
+5:30时区。怎么做?
from pytz import all_timezones, timezone
from datetime import datetime
def get_cuurent_time(utc_value):
for zone in all_timezones:
tz = timezone(zone)
if utc_value in str(datetime.now(tz)):
return datetime.now(tz)
print (get_cuurent_time("+05:30"))
我做了,不打扰:),但如果还有其他任何方式,请告诉我。