简体   繁体   中英

Datetime's timestamp function not matching expected UNIX time

The following

import datetime as dt

dt.datetime(2019, 7, 21).timestamp()

returns

1563663600.0 .

However, if I look on https://www.unixtimeconverter.io/list/2019/july , then I see that the expected Unix time for this date is 1563667200.

Why the discrepancy?

datetime doesn't assume UTC by default, so you need to specify it.

dt.datetime(2019, 7, 21, tzinfo=dt.timezone.utc).timestamp()

1563667200

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM