[Python-Dev] Issue 2736: datetimes and Unix timestamps

Dirkjan Ochtman dirkjan at ochtman.nl
Tue Jun 5 16:19:50 CEST 2012


On Tue, Jun 5, 2012 at 3:45 PM, Guido van Rossum <guido at python.org> wrote:
> For datetimes with tzinfo, dt.totimestamp() should return (dt -
> epoch).total_seconds() where epoch is
> datetime.datetime.fromtimestamp(0, datetime.timezone.utc); for
> timezones without tzinfo, a similar calculation should be performed
> assuming local time. The utctotimestamp() method should insist that dt
> has no tzinfo and then do a similar calculation again assuming the
> implied UTC timezone.

It would be nice if utctotimestamp() also worked with datetimes that
have tzinfo set to UTC.

And while I don't think we really need it, if there are concerns that
some other epochs may be useful, we could add an optional epoch
argument.

Cheers,

Dirkjan


More information about the Python-Dev mailing list