0

I'm trying to perform a, to me, simple task of generating a current date/time combo at a speficic time zone. All I see is suggestions to use pytz even though datetime includes the tzinfo class to deal with timezones. However, if I try to use tzinfo, it does not work:

>>> from datetime import datetime, tzinfo
>>> d = datetime.now(tzinfo.tzname("EDT"))
TypeError: descriptor 'tzname' requires a 'datetime.tzinfo' object but received a 'str'

The docs say you can use a time zone name like "EDT" or "GMT". What's wrong with this?

mart1n
  • 5,969
  • 5
  • 46
  • 83

1 Answers1

1

The function tzinfo.tzname does the opposite of what you think it does.

It takes a datetime object and returns a string indicating the time zone.

merlin2011
  • 71,677
  • 44
  • 195
  • 329