This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python default date does not match Unix time
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Itay Grudev, belopolsky, vstinner
Priority: normal Keywords:

Created on 2016-03-24 12:45 by Itay Grudev, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg262337 - (view) Author: Itay Grudev (Itay Grudev) Date: 2016-03-24 12:45
When parsing a time only string like:

```
datetime.datetime.strptime('13:48:25', '%H:%M:%S')
```

This produces:

```
datetime.datetime(1900, 1, 1, 13, 48, 25)
```

Not that the year is `1900` which just doesn't make sense. This will produce `-1` when you attempt to get it's UNIX timestamp. And while that sounds weird it is very useful.

The default year should be 1970. And this will resolve the issue.
msg262339 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-24 12:52
The year 1900 is a delibrate choice, it's even documented:
https://docs.python.org/dev/library/datetime.html#strftime-and-strptime-behavior

"For time objects, the format codes for year, month, and day should not be used, as time objects have no such values. If they’re used anyway, 1900 is substituted for the year, and 1 for the month and day."

> The default year should be <whatever>

If you expect a year, you can easily use dt.replace(year=<whatever>), no?

Or start with a datetime.time object and then build a datetime.datetime using the time? It's up to you.

We will not change a default value, it will break the backward compatibility.
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70822
2016-03-24 12:52:44vstinnersetstatus: open -> closed

nosy: + vstinner, belopolsky
messages: + msg262339

resolution: not a bug
2016-03-24 12:45:38Itay Grudevcreate