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.
Created on 2008年03月27日 07:27 by mark, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg64578 - (view) | Author: Mark Summerfield (mark) * | Date: 2008年03月27日 07:27 | |
# If you run the code below on Py30a3 you get the output shown at the end
import calendar, datetime, time
pastdate = datetime.datetime(1969, 12, 31)
print(pastdate)
timestamp = calendar.timegm(pastdate.utctimetuple())
print(timestamp)
try:
pastdate_x = datetime.datetime.utcfromtimestamp(timestamp)
except ValueError as err:
print("FAIL", err)
try:
print(time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(timestamp)))
except ValueError as err:
print("FAIL", err)
r"""
Python 30a3
Windows output:
1969年12月31日 00:00:00
-86400
FAIL timestamp out of range for platform localtime()/gmtime() function
FAIL (22, 'Invalid argument')
Linux output:
1969年12月31日 00:00:00
-86400
1969年12月31日T00:00:00
"""
# What this appears to show is that you can't round-trip between
datetimes and timestamps on Windows for dates prior to 1970
|
|||
| msg64583 - (view) | Author: Christian Heimes (christian.heimes) * (Python committer) | Date: 2008年03月27日 11:50 | |
It's most likely a platform limitation. Some platforms doen't support negative time stamps. |
|||
| msg75722 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2008年11月11日 02:58 | |
If you doesn't care to the time zone (UTC), use: >>> datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=-86400) datetime.datetime(1969, 12, 31, 0, 0) This code is portable on Windows, Linux but also works with IronPython: http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=7269 |
|||
| msg124481 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年12月22日 03:11 | |
Indeed, the time module is documented as not handling timestamps before the epoch. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:32 | admin | set | github: 46746 |
| 2010年12月22日 03:11:09 | r.david.murray | set | status: open -> closed nosy: + r.david.murray messages: + msg124481 resolution: not a bug stage: resolved |
| 2008年11月11日 02:58:04 | vstinner | set | nosy:
+ vstinner messages: + msg75722 |
| 2008年03月27日 11:50:52 | christian.heimes | set | nosy:
+ christian.heimes messages: + msg64583 |
| 2008年03月27日 07:27:05 | mark | create | |