Write a Python program to generate RFC 3339 timestamp


The program is written in Python and uses the datetime module from the datetime library. The first line from datetime import datetime, timezone imports the datetime and timezone classes from the datetime library.

The next line creates a datetime object lt that represents the current date and time, as well as the local time zone. This is done by calling datetime.now(timezone.utc), which returns the current date and time in UTC (Coordinated Universal Time), and then calling the astimezone method on the result, which returns the equivalent date and time in the local time zone.

Finally, the print function is used to output the value of lt in ISO format. The isoformat method returns a string representation of the datetime object in ISO 8601 format, which is a standardized format for representing dates and times.

Source Code

from datetime import datetime, timezone
lt = datetime.now(timezone.utc).astimezone()
print(lt.isoformat())

Output

2022-09-24T12:37:07.729672+05:30

Example Programs