对于 pandas 时间戳:
pd.Timestamp.today(tz = 'Europe/London')
如何按以下方式格式化时间(时区组件中存在冒号)?:
'2023-12-04 16:08:02+00:00'
Pandas 声称包含所有原生 Python strftime 指令: https://pandas.pydata.org/docs/reference/api/pandas.Period.strftime.html
Python 声称支持
'%:z'
指令,这正是我所需要的:
https://docs.python.org/3/library/datetime.html
因此,以下代码:
pd.Timestamp.today(tz = 'Europe/London').strftime('%Y-%m-%d %X%:z')
应该给出我想要的答案,但反而提出了
ValueError: Invalid format string
,因为它无法识别'%:z'
。
isoformat
吗?
ts = pd.Timestamp.today(tz="Europe/London")
out = ts.isoformat(timespec="seconds", sep=" ") # 2023-12-04 17:27:28+00:00