Date, time, and Unix#

Python module dateutil can be used to parse dates in string format and convert them into date objects, as well as to convert them into Unix time - and viceversa.

Parse a date in string format#

Script [s5.15] #
 1# Import the module to interpret strings as dates
 2import dateutil.parser as parser
 3
 4# Assign a string to the variable 'text'
 5text = "Friday 15th April 2022 17:10:05 +0200"
 6# Process 'text' through the date parsers, and assign it to the variable 'date'
 7date = parser.parse(text)
 8# Print the date object using ISO 8601 format
 9print(date.isoformat())
10# output: 2022-04-15T17:10:05+02:00