20221218星期日:
格式轉換中,加上 %p 就可以顯示AM、PM:
import time
import datetime
t1 = time.strftime("%Y-%m-%d %H:%M:%S %p")
print(type(t1),t1) # <class 'str'> 2022-12-18 14:37:20 PM
# strftime 時間類型轉換成字符串:
t2 = datetime.datetime.strftime(datetime.datetime.today(),"%Y-%m-%d %H:%M:%S %p")
print(type(t2),t2) # <class 'str'> 2022-12-18 14:37:20 PM
# strptime 字符串轉換成時間:
t3 = datetime.datetime.strftime(datetime.datetime.strptime("2022-12-18 10:38:41","%Y-%m-%d %H:%M:%S"),"%Y-%m-%d %H:%M:%S %p")
print(type(t3),t3) # <class 'str'> 2022-12-18 10:38:41 AM
,
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!