gpt4 book ai didi

python - 如何获取 ISO 日历格式的年-周格式?

转载 作者:行者123 更新时间:2023-12-01 23:40:01 26 4
gpt4 key购买 nike

我正在尝试获取 ISO 日历格式的当前日期,如下所示以及周的零填充?

2019/W06

我尝试了以下方法,但更喜欢使用 strftime ,因为它更容易阅读。

print(str(datetime.datetime.today().isocalendar()[0]) + '/W' + str(datetime.datetime.today().isocalendar()[1]))
2019/W6

最佳答案

使用以下代码:

print(datetime.now().strftime('%Y/W%V'))

%Y Year with century as a decimal number.

%V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.

https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior

关于python - 如何获取 ISO 日历格式的年-周格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54526629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com