How to get current time in Pacific Timezone when i

2019-08-30 08:22发布

I'm working in an environment (AWS Lambda) where import pytz doesn't work.

The environment is set to UTC.

How can I get the current time in the U.S. Pacific Timezone in this environment?

I need something simple, and low-maintenance. Somehow forcing import pytz to work would be ideal, and I hope to avoid having to copy the entire pytz library into my own script.

Details

What have I tried so far? I tried using import pytz, and it failed with module not found.

Example code? I tried this, straight from another question on SO:

import pytz
import datetime as DT

eastern = pytz.timezone('US/Eastern')
utc = pytz.utc
test = '2013-03-27 23:05'

1条回答
我命由我不由天
2楼-- · 2019-08-30 08:34

If you don't have access to pytz in your environment, maybe you have access to python-dateutil. In that case you can do:

import datetime
import dateutil.tz

eastern = dateutil.tz.gettz('US/Eastern')
datetime.datetime.now(tz=eastern)
查看更多
登录 后发表回答