Python 3 – time altzone() Method
The altzone()
method is a function in the Python programming language that is used to get the number of seconds east of UTC (Coordinated Universal Time) during the daylight-saving time. The output is always negative and represents the offset of the local standard timezone from the Coordinated Universal Time (UTC) in seconds.
Syntax
time.altzone()
Parameters
There are no parameters for this method.
Return Value
The altzone()
method returns an integer value.
Example
Here’s an example of the altzone()
method usage:
import time
# Get the daylight-saving time offset
print("Current daylight-saving time offset: %d seconds." % time.altzone())
output:
Current daylight-saving time offset: -14400 seconds.
The output shows that the daylight-saving time offset at the present moment is -14400 seconds which is equal to 4 hours (60 * 60 * 4 = 14400).
Explanation
The altzone()
method calculates and returns the offset of the local time zone from Coordinated Universal Time (UTC) for the daylight-saving time. If the local standard time zone is being used, the function timezone()
shoud be used instead.
It’s important to note that not all local time zones use daylight-saving time. Some countries and territories use year-round standard time or have abolished the changes to daylight-saving schedules.
Conclusion
In conclusion, the altzone()
method is a convenient function in Python that returns the number of seconds east of UTC during the daylight-saving time. It’s useful for various time-related applications and programs. The timezone()
function can be used to get the number of seconds east of UTC for the local standard time zone.