Tal Einat <talei...@gmail.com> added the comment:
At least with Python 3.7.0, the equivalence is not complete: datetime.strptime() is better, since it retains both microseconds and timezone data. See examples below. >>> from datetime import datetime, timezone >>> import time >>> s = datetime.strftime(datetime.now(), '%a %b %d %H:%M:%S %f') >>> s 'Fri Oct 12 11:33:32 999810' >>> datetime.strptime(s, '%a %b %d %H:%M:%S %f') datetime.datetime(1900, 10, 12, 11, 33, 32, 999810) >>> datetime(*time.strptime(s, '%a %b %d %H:%M:%S %f')[:6]) datetime.datetime(1900, 10, 12, 11, 33, 32) >>> s2 = datetime.strftime(datetime.now(timezone(timedelta(hours=1))), '%a %b >>> %d %H:%M:%S %f%z') >>> s2 'Fri Oct 12 09:48:40 347076+0100' >>> datetime.strptime(s2, '%a %b %d %H:%M:%S %f%z') datetime.datetime(1900, 10, 12, 9, 48, 40, 347076, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))) >>> datetime(*time.strptime(s2, '%a %b %d %H:%M:%S %f%z')[:6]) datetime.datetime(1900, 10, 12, 9, 48, 40) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue27741> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com