【问题标题】:Python Date-FormatPython 日期格式
【发布时间】:2021-04-13 15:18:43
【问题描述】:

我想将输入日期时间格式更改为输出日期时间格式: 输入日期时间格式 = 2021 年 4 月 5 日 06:46:16 GMT

然后我做了:

input = input.replace(newdate[:5],"") #2021 年 4 月 5 日 06:46:16 GMT

输出日期时间格式 05/04/2021 06:46:16

【问题讨论】:

  • 你看过datetime模块吗?

标签: python date format


【解决方案1】:
import datetime
input_format = '05 Apr 2021 06:46:16 GMT'
input_list = input_format.split() #split the string and store in list
modified_input = " ".join(input_list[0:-1]) #removing the last element which is GMT and then joining all the strings in the list
output_format = datetime.datetime.strptime(modified_input, "%d %b %Y %H:%M:%S")
print(output_format.strftime("%d/%m/%Y %H:%M:%S"))

【讨论】:

    猜你喜欢
    • 2012-08-10
    • 1970-01-01
    • 2012-05-19
    • 2016-03-06
    • 2020-07-25
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多