months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] USE_24HR_TIME = False def time_transform(val): # val is in format '2021-03-25T20:07:39.402Z' dstStart = {2021: 14, 2022: 13, 2023: 12, 2024: 10, 2025: 9, 2026: 8, 2027: 14, 2028: 12, 2029: 11, 2030: 10, 2031: 9} dstStop = {2021: 7, 2022: 6, 2023: 5, 2024: 3, 2025: 2, 2026: 1, 2027: 7, 2028: 5, 2029: 4, 2030: 3, 2031: 2} if val == None: val = "When: Unavailable" year = int(val[0:4]) month = int(val[5:7]) day = int(val[8:10]) hour = int(val[11:13]) # hour is in UTC if month in range(3, 12): if month == 3 and day >= int(dstStart[year])+1 or month == 3 and day == int(dstStart[year]) and hour >= 7: timezoneOffset = 4 elif month == 11 and day <= int(dstStop[year]): if day <= int(dstStop[year])-1 or day == int(dstStop[year]) and hour <= 6: timezoneOffset = 4 else: timezoneOffset = 5 elif month in range(4,11): timezoneOffset = 4 else: timezoneOffset = 5 else: timezoneOffset = 5 hour = hour - timezoneOffset if hour < 0: hour = hour + 24 day = day -1 min = int(val[14:16]) if USE_24HR_TIME: timestring = "%d:%02d" % (hour, min) elif hour > 12: timestring = "%d:%02d pm" % (hour-12, min) else: timestring = "%d:%02d am" % (hour, min) return "%s %d, %d, at %s" % (months[month-1], day, year, timestring) testval = '2021-11-07T08:00:39.402Z' print(testval) print(time_transform(testval))