# time.gmtime

Discussion in 'Python' started by asit, Jan 25, 2008.

1. ### asitGuest

we know that time.gmtime(secs) takes a parameter secs. what does this
secs suggest ??What is it's significance ??

asit, Jan 25, 2008

2. ### Harald KarnerGuest

asit wrote:
> we know that time.gmtime(secs) takes a parameter secs. what does this
> secs suggest ??What is it's significance ??

>>> import time
>>> help (time.gmtime)

Help on built-in function gmtime in module time:

gmtime(...)
gmtime([seconds]) -> (tm_year, tm_mon, tm_day, tm_hour, tm_min,
tm_sec, tm_wday, tm_yday, tm_isdst)

Convert seconds since the Epoch to a time tuple expressing UTC
(a.k.a. GMT). When 'seconds' is not passed in, convert the current time

>>> time.gmtime (0)

(1970, 1, 1, 0, 0, 0, 3, 1, 0)
>>>

Harald Karner, Jan 25, 2008

3. ### Paul BoddieGuest

On 25 Jan, 11:43, asit <> wrote:
> we know that time.gmtime(secs) takes a parameter secs. what does this
> secs suggest ??What is it's significance ??

From the documentation [1] with some editing:

"""
gmtime([secs])

Convert a time expressed in seconds since the epoch to a time
structure employing UTC. If secs is not provided or None, the current
time as returned by time.time() is used.

The epoch is the point where the time starts. On January 1st of that
year, at 0 hours, the ``time since the epoch'' is zero. For Unix, the
epoch is 1970. To find out what the epoch is, look at gmtime(0).
"""

So, the significance of the secs parameter is that it indicates a
specific point in time. Generally, you'll get this from functions like
time.time or from "UNIX timestamps" stored in things like files and
databases where people have wanted to indicate a point in time without
having to mention things like dates, times and timezones.

Paul

P.S. The datetime module is preferable to the time module, really. The
latter can drive you quite mad when things like timezones start to be
taken into account.

[1] http://docs.python.org/lib/module-time.html

Paul Boddie, Jan 25, 2008