You can download this code by clicking the button below.
This code is now available for download.
This function takes a tuple of timestamps in the format (year, month, day, hour, minute, second) and formats it into a readable string format.
Technology Stack : datetime, time, calendar
Code Type : Time formatting function
Code Difficulty : Intermediate
def format_time(time_tuple):
from datetime import datetime
from time import strptime
from calendar import month_abbr, weekday_abbr
formatted_time = datetime.strptime(str(time_tuple), '%Y%m%d%H%M%S')
return f"{formatted_time.strftime('%Y-%m-%d %H:%M:%S')} ({weekday_abbr[formatted_time.weekday()]}, {month_abbr[formatted_time.month]})"