Python datetime.utcoffset() Method with Example
The utcoffset() function is used to return a timedelta object that represents the difference between the local time and UTC time.
- This function is used in used in the datetime class of module datetime.
- Here range of the utcoffset is “timedelta(hours=24) <= offset <= timedelta(hours=24)”.
- If the offset is east of UTC, then it is considered positive and if the offset is west of UTC, then it is considered negative. Since there are 24 hours in a day, -timedelta(24) and timedelta(24) are the largest values possible.
Parameters: This function does not accept any parameter.
Return values: This function returns a timedelta object representing the difference between the local time and UTC time.
Example 1: Here output is None because now() function returns date and time in UTC format, hence the difference between the local time i.e, returned by now() function and UTC time is none.
Example 2: Finding the offset of time
Time ahead of UTC by: 5:30:00
Example 3: Finding time offset
Time ahead of UTC by: 9:00:00