Links

Convert Datetime with Timezone to ISO 8601 date string

Tags: #python #datetime #timezone #iso8601 #string #conversion
Author: Florent Ravenel
Description: This notebook will demonstrate how to convert a datetime with timezone to an ISO 8601 date string.
References:

Input

Import libraries

from datetime import datetime
import pytz

Setup Variables

  • date_time: datetime with timezone
date_time = datetime(2020, 8, 1, 12, 0, 0, tzinfo=pytz.timezone("Europe/Paris"))
print(date_time)

Model

Convert datetime with timezone to ISO 8601 date string

iso_date_string = date_time.isoformat()

Output

Display result

print(iso_date_string)