142 of 151 menu

The time method of datetime module

The time method of the datetime module creates a time object. In the first parameter of the method we specify the hours, in the second parameter - the minutes, in the third - the seconds.

Syntax

import datetime datetime.time(hours, minutes, seconds)

Example

Let's create a new time object:

import datetime res = datetime.time(12, 59, 59) print(res.hour) print(res.minute) print(res.second)

The result of the executed code:

12 59 59

See also

  • method date of module datetime,
    which creates a new object with a date
  • method today of module datetime,
    which returns the current date
  • method now of module datetime,
    which returns the current time
  • method datetime of module datetime,
    which creates a date and time object
  • method strftime of module datetime,
    which creates a formatted string with date and time
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