13281.將字符串轉爲日期

題目鏈接

題目受版權保護,不可轉載,參見上述鏈接

input

2019-03-18
18 Mar 2019
19-03-18
2019-03-18 14:03:15
2019-03-18 02:03:15PM
2019-03-18 14:03:15.123456
2019-03-18%14:03:15

output

2019-03-18 00:00:00
2019-03-18 00:00:00
2019-03-18 00:00:00
2019-03-18 14:03:15
2019-03-18 14:03:15
2019-03-18 14:03:15.123456
2019-03-18 14:03:15

My Code

import datetime

# 2019-3-18
print(datetime.datetime.strptime(input(), "%Y-%m-%d"))

# 18 Mar 2019
print(datetime.datetime.strptime(input(), "%d %b %Y"))

# 19-03-18
print(datetime.datetime.strptime(input(), "%y-%m-%d"))

# 2019-03-18 14:03:15
print(datetime.datetime.strptime(input(), "%Y-%m-%d %H:%M:%S"))

# 2019-03-18 02:03:15PM
print(datetime.datetime.strptime(input(), "%Y-%m-%d %I:%M:%S%p"))

# 2019-03-18 14:03:15.123456

print(datetime.datetime.strptime(input(), "%Y-%m-%d %H:%M:%S.%f"))


# 2019-03-18%14:03:15
print(datetime.datetime.strptime(input(), "%Y-%m-%d%%%H:%M:%S"))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章