UTC offset

UTC offset:

- UTC stands for (Universal time coordinated).

- UTC offset is the difference in hours(HH) and minutes(MM) between UTC and local time, at a specific place.

For Example- India's standard time zone has 5 hours and 30 minutes difference.


Zero UTC offset:

Below code explanation:

- we import datetime and timezone class from the datetime module to work with timezone UTC offset.

- We create the timezone object at the timezone.UTC which means Zero UCT offset in tz named variable.

- We create the datetime object at a specific datetime with “tzinfo=” that accepts the timezone UTC in dt named variable.

- The “tzinfo=class is used to access the information of timezone UTC.



Output:

- After print, we get the Datetime with Zero UTC offset.

- Timezone UTC format - (“+HH:MM” for east time UTC, “-HH:MM“ for west time UTC)



Timedelta() UTC offset:

Below code explanation:

- We import datetime, timezone, and timedelta class from the datetime module to work with timedelta UTC offset.

- We create the timezone object at India's standard timezone UTC = (05:30) through the timedelta() class in the tz named variable.

- We create the datetime object at a specific datetime with “tzinfo=” that accepts the timezone UTC in dt named variable.

- The “tzinfo=” class is used to access the information of timezone UTC.



Output:

- After printing, we get the Datetime with India's standard timezone UTC = (05:30).

Timezone UTC format - (“+HH:MM” for east time UTC, “-HH:MM“ for west time UTC)


Comments