2

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

eastern = pytz.timezone('US/Eastern')
utc = pytz.utc
test = '2013-03-27 23:05'
Alex R
  • 11,364
  • 15
  • 100
  • 180

1 Answers1

4

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)
Dunedan
  • 7,848
  • 6
  • 42
  • 52