Python當前時間是一年中第幾周

2021-08-21 03:19:44 字數 890 閱讀 7348

python返回當前時間是一年中第幾周有好多種方法

方法一:

>>> import time

>>> print(time.strftime("%w"))

26

方法二:

>>> from datetime import datetime

>>> datetime.now().isocalendar() # 今年2023年;第26周; 周6; 今天2023年06月30日

(2018, 26, 6)

>>> datetime.now().isocalendar()[1] # 索引為[1],就可以求出一年的第多少周

26>>> datetime(2018,6,30).isocalendar()[1] # 或者填好今天具體日期來獲取第多少周

26

方法三:

>>> import time

>>> time.localtime()

time.struct_time(tm_year=2018, tm_mon=6, tm_mday=30, tm_hour=9, tm_min=53, tm_sec=10, tm_wday=5, tm_yday=181, tm_isdst=0)

>>> time.localtime()[7] # 一年中的第181天

181

>>> time.localtime()[7]/7+1 # 一年中的第26周

26

C 計算當前日期是一年中的第幾周

方法一 private int weekofyear string date else 方法二 system.globalization.gregoriancalendar gc new system.globalization.gregoriancalendar int weekofyear gc...

又是一年中秋

不同於別的節日,上大學以來,每年的中秋過的還都蠻有節日氣氛的。糾結三天的數模國賽終於也告一段落,雖然最終還是迫不得已的通宵了,而且在最後趕的十分急,但總算是完成了,感覺還是比較不錯的。其間也發生了一些我不願意發生的事情,也差點為此悲劇了。不過對於某些事情,我還是處於一種坦然的態度,畢竟對於學術而言,...

輸入日期判斷這天是一年中第幾天

判斷這天是一年中第幾天 nonleap 0 31,28 31,30 31,30 31,31 30,31 30,31 leap 0 31,29 31,30 31,30 31,31 30,31 30,31 sum 0 date input 請輸入想要查詢的年月日,格式如 x xx xx n date d...