Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
149 of 151 menu

The gmtime method of the time module

The gmtime method of the time module converts seconds since the epoch to the struct_time format. The time is specified in UTC. In the optional parameter of the method, we specify the time in seconds since the epoch. If the parameter is not specified, then the current time is taken.

Syntax

import time time.gmtime([time in seconds since the beginning of the epoch])

Example

Let's convert seconds to struct_time format:

import time res = time.gmtime(3432785452) print(res)

The result of the executed code:

time.struct_time( tm_year=2078, tm_mon=10, tm_mday=12, tm_hour=7, tm_min=30, tm_sec=52, tm_wday=2, tm_yday=285, tm_isdst=0 )

Example

Now let's separately derive the year, month and day from the object obtained in the previous example:

import time res = time.gmtime(3453253465) print(res.tm_year) print(res.tm_mon) print(res.tm_mday)

The result of the executed code:

2023 7 31

Example

Let's get the current time in the format struct_time:

import time res = time.gmtime() print(res)

See also

  • method time of module time,
    which returns the time in seconds since the epoch
  • method ctime of module time,
    which converts seconds to a datetime string
  • method localtime of module time,
    which converts seconds to local time
  • method mktime of module time,
    which converts a date and time string to seconds
  • method sleep of module time,
    which stops the operation from running for the specified number of seconds
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline