Hello,
I am sorry, I am kind of lost and I would be really grateful to receive
some help.
Basically, I have a list of timestamps expressed as a strings as below, and
I would like them expressed in UTC. But there seems to be a trouble during
the offset, which is applied the other way round.
The input timestamps look like:
0 'Sat Mar 30 2019 21:00:00 GMT+0100'
Adding them in a panda dataframe with to_datetime function, they read then:
GC['Time'] = pd.todatetime(my_timestamps)
GC['Time']
…
[View More]0 2019-03-30 21:00:00-01:00
If I further ask:
GC['Time'][0]
datetime.datetime(2019, 3, 30, 21, 0, tzinfo=tzoffset(None, -3600))
It seems, AFAIK, OK.
But then if I want to resolve the offset so as to have time expressed in
UTC time, I get:
GC['Test'] = pd.to_datetime(GC['Time'],utc=True)
0 2019-03-30 22:00:00+00:00
The offset has bee applied the other way round.
Correct timestamp in UTC would be 20:00:00
Please, what should I do to have these timestamps correctly expressed in
UTC time?
I thank you in advance for your help.
I am so sorry to intrude the mailing list with this question, but I am
unable to move forward from this point.
I thank you again,
Bests,
Pierre
[View Less]
Should `strptime`, when passed a %Z format specifier, parse more than just
GMT, UTC, and the local time zone given that we now have the IANA database
in the stdlib via PEP 615 since Python 3.9?
The regex for the %Z specifier appears to come from TimeRE and always has
GMT, UTC, and then the local time zone.
>>> from _strptime import TimeRE
>>> t = TimeRE()
>>> t['Z']
'(?P<Z>cst|gmt|utc|cdt)'
>>> from datetime import datetime
>>> datetime.…
[View More]strptime('2016-12-04 08:00:00 CST', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 CDT', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 UTC', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z')
datetime.datetime(2016, 12, 4, 8, 0)
>>> datetime.strptime('2016-12-04 08:00:00 EST', '%Y-%m-%d %H:%M:%S %Z')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/home/eugene/src/cpython/Lib/_strptime.py", line 568, in
_strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/eugene/src/cpython/Lib/_strptime.py", line 349, in
_strptime
raise ValueError("time data %r does not match format %r" %
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: time data '2016-12-04 08:00:00 EST' does not match format
'%Y-%m-%d %H:%M:%S %Z'
There have been some discussions and issues with regard to this in the past:
- https://github.com/python/cpython/issues/66571
- https://github.com/python/cpython/issues/66616
I was interested in taking a look at this, but I wanted to reach out and
know if it was something that would be desirable and what others' thoughts
were.
Thanks,
Eugene
[View Less]