w3resource

Python: Find out what the epoch is on a given platform

Python Datetime: Exercise-55 with Solution

The epoch is the point where time starts, and is platform dependent. For Unix, the epoch is January 1, 1970, 00:00:00 (UTC). Write a Python program to find out what the epoch is on a given platform. Convert a given time in seconds since the epoch.

Sample Solution:

Python Code:

import time
print("\nEpoch on a given platform:")
print(time.gmtime(0))
print("\nTime in seconds since the epoch:")
print(time.gmtime(36000))

Sample Output:

Epoch on a given platform:
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)

Time in seconds since the epoch:
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=10, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)

Flowchart:

Flowchart: Find out what the epoch is on a given platform.

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to set the default timezone used by all date/time functions.
Next: Write a Python program to get time values with components using local time and gmtime

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.