Compare commits
2 Commits
2aeaadfe18
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fe4883cde8 | |||
| c048527f38 |
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
|
||||
d = datetime(year=2020, month=11, day=4, hour=14, minute=53, second=0)
|
||||
|
||||
# Direttive usate con strftime:
|
||||
# %Y anno con 4 cifre -> 2020
|
||||
# %y anno con 2 cifre -> 20
|
||||
# %m mese numerico -> 11
|
||||
# %B nome mese completo -> November
|
||||
# %b nome mese abbreviato -> Nov
|
||||
# %d giorno del mese -> 04
|
||||
# %H ora formato 24h -> 14
|
||||
# %M minuti -> 53
|
||||
# %S secondi -> 00
|
||||
# %p AM/PM -> PM
|
||||
# %a giorno abbreviato -> Wed
|
||||
# %A giorno completo -> Wednesday
|
||||
# %w giorno settimana -> 3
|
||||
# %j giorno dell'anno -> 309
|
||||
# %W numero settimana -> 44
|
||||
|
||||
print(d.strftime("%Y/%m/%d %H:%M:%S"))
|
||||
print(d.strftime("%y/%B/%d %H:%M:%S %p"))
|
||||
print(d.strftime("%a, %Y %b %d"))
|
||||
print(d.strftime("%A, %Y %B %d"))
|
||||
print(d.strftime("Weekday: %w"))
|
||||
print(d.strftime("Day of the year: %j"))
|
||||
print(d.strftime("Week number of the year: %W"))
|
||||
@@ -0,0 +1,29 @@
|
||||
from calendar import Calendar
|
||||
|
||||
class MyCalendar(Calendar):
|
||||
|
||||
def count_weekday_in_year(self, year, weekday):
|
||||
|
||||
count = 0
|
||||
|
||||
for month in range(1, 13):
|
||||
|
||||
month_calendar = self.monthdays2calendar(year, month)
|
||||
|
||||
for week in month_calendar:
|
||||
|
||||
for day_number, day_weekday in week:
|
||||
|
||||
if day_number != 0 and day_weekday == weekday:
|
||||
count += 1
|
||||
|
||||
return count
|
||||
|
||||
|
||||
my_calendar = MyCalendar()
|
||||
|
||||
|
||||
result = my_calendar.count_weekday_in_year(2000, 6)
|
||||
|
||||
|
||||
print(result)
|
||||
Reference in New Issue
Block a user