-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice2.py
More file actions
19 lines (15 loc) · 738 Bytes
/
practice2.py
File metadata and controls
19 lines (15 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from datetime import datetime
def convert_date(iso_string):
"""Converts and ISO formatted date into a human-readable format.
Args:
iso_string: An ISO date string.
Returns:
A date formatted like: Weekday Date Month Year e.g. Tuesday 06 July 2021
"""
# %A Weekday, full version -> Wednesday
# %d Day of month 01-31 -> 31
# %B Month name, full version -> December
# %Y Year, full version -> 2018
date = datetime.fromisoformat(iso_string) # strptime takes two arguments: 1st - date looking string, 2st - the actual date instance
return date.strftime("%A %d %B %Y") # strftime changes the actual date instance to a different format
print(convert_date("2021-07-02T07:00:00+08:00"))