简体   繁体   中英

django date output format with 2 digits with leading zeros

我的date=timezone.now().date()输出如下: datetime.date(2016, 2, 25) ,但我更喜欢输出有2位数字,例如datetime.date(2016, 02, 25)

You can use the strftime method:

from django.utils import timezone

date = timezone.now().date()
print date.strftime("%Y/%m/%d")
# Prints '2016/02/25'

You can check out this unofficial strftime reference for more details, or the official docs here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM