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:)
150 of 151 menu

The mktime method of the time module

The mktime method of the time module converts a string with a date and time into seconds. In the method parameter, we specify the time structure struct_time or a tuple of 9 elements with the mandatory dst flag, which displays local time.

Syntax

import time time.mktime(time structure or tuple)

Example

Let's convert a date and time string to seconds:

import time struct_time = time.strptime('10/10/2020 10:15', '%d/%m/%Y %H:%M') res = time.mktime(struct_time) print(res)

The result of the executed code:

1602314100.0

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 gmtime of module time,
    which converts seconds to UTC format
  • 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