本文介紹了僅使用字符串 format() 方法的 Python 格式日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
僅使用 .format
方法在 python 中格式化日期的快速方法是什么?我知道有一種方法可以在不使用 strftime
的情況下做到這一點.我需要更優(yōu)雅的方法.
What is the quick way to format date in python using only .format
method?
I know there is a way to do it without using strftime
. I need more elegant method.
推薦答案
我知道一個很好的方法,不為人知,但非常有用.
I know a good method which is not widely known, but very useful.
你可以這樣做:
from datetime import datetime
'{:%Y-%m-%d %H:%M}'.format(datetime(2018, 12, 28, 10, 30))
輸出為2018-12-28 10:30
這篇關(guān)于僅使用字符串 format() 方法的 Python 格式日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!