How I can get the month name from the month number?
## # Python's program to get the month name from the month number import calendar import datetime # Month name from number print("Month name from number 5:") month_num = 1 month_abre = datetime.date(2015, month_num, 1).strftime('%b') month_name = datetime.date(2015, month_num, 1).strftime('%B') print("Short Name:", month_abre) print("Full Name:", month_name) print("\nList of all months from calendar") # Print list of all months from calendar for month_val in range(1, 13): print(calendar.month_abbr[month_val], "-", calendar.month_name[month_val])
Sample output of above program.
C:\programs\time>pep8 --first example17.py
C:\programs\time>python example17.py
Month name from number 5:
Short Name: Jan
Full Name: January
List of all months from calendar
Jan - January
Feb - February
Mar - March
Apr - April
May - May
Jun - June
Jul - July
Aug - August
Sep - September
Oct - October
Nov - November
Dec - December
C:\programs\time>
C:\programs\time>python example17.py
Month name from number 5:
Short Name: Jan
Full Name: January
List of all months from calendar
Jan - January
Feb - February
Mar - March
Apr - April
May - May
Jun - June
Jul - July
Aug - August
Sep - September
Oct - October
Nov - November
Dec - December
C:\programs\time>
2019-02-17T12:00:00+05:30
2019-02-17T12:00:00+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution