from datetime import datetime
string_time = "2021-01-29T13:29:19.668Z"
# see https://strftime.org/ for definitions of strftime directives
dt_format = "%Y-%m-%dT%H:%M:%S.%fZ"
output_format = "%b %d, %Y @ %-I:%-M%p" # the %p is uppercase AM or PM
output = datetime.strftime(datetime.strptime(string_time, dt_format), output_format)
# lower case the last 2 characters of output
# and join with all characters except the last 2
print(''.join((output[:-2], output[-2:].lower())))
我使用了datetime模块。 并使用split函数将日期与时间以及其他内容分开
您可能想探索pendulum
pendulum
是Python的datetime
变得简单了只需使用以下软件安装:
适用于您的案例的用法:
输出:
编辑:要获取
EST
中的时间(修改时间),只需执行以下操作:输出:
但是,如果您不想修改输出,只想设置时区,请尝试以下操作:
输出:
输出:
Jan 29, 2021 @ 1:29pm
相关问题 更多 >
编程相关推荐