[英]Convert Twitter New Date Format to Date Time ( %Y-%m-%d %H:%M%S' )
Twitter's new date format used to be Twitter 的新日期格式曾经是
%a %b %d %H:%M%S 0000 %Y
Now however it is like this...然而现在是这样的……
df.created_at[0]
'2021-03-08T19:14:00.000Z'
How do we convert that?我们如何转换它? What is confusing me is figuring out how to process the "T" and the ".000Z" portions.令我困惑的是弄清楚如何处理“T”和“.000Z”部分。
Thanks!谢谢!
E: E:
To be clear,https://developer.twitter.com/en/docs/twitter-ads-api/timezones says what the strptime is.需要明确的是,https://developer.twitter.com/en/docs/twitter-ads-api/timezones说明了 strptime 是什么。 However, it doesn't seem to work for me.但是,它似乎对我不起作用。
Trying my best guess...尝试我最好的猜测...
datetime.strftime( datetime.strptime( df.created_at[0], '%Y-%m-%dT%H:%M:%S.00%z' ), '%Y-%m-%d %H:%M:%S' )
ValueError: time data '2021-03-08T19:14:00.000Z' does not match format '%Y-%m-%dT%H:%M:%S.00%z'
Trying their exact match...尝试他们的精确匹配...
datetime.strftime( datetime.strptime( df.created_at[0], '%Y-%m-%dT%l:%M:%S%z' ), '%Y-%m-%d %H:%M:%S' )
ValueError: 'l' is a bad directive in format '%Y-%m-%dT%l:%M:%S%z'
>>> datetime.strftime( datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.00%z' ), '%Y-%m-%d %H:%M:%S' )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2021-03-08T19:14:00.000Z' does not match format '%Y-%m-%dT%H:%M:%S.00%z'
>>> datetime.strftime( datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.000%z' ), '%Y-%m-%d %H:%M:%S' )
'2021-03-08 19:14:00'
You were just missing a 0
in your parsing string.您只是在解析字符串中缺少一个0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.