143 of 151 menu

The now method of the datetime module

The now method of the datetime module returns the current time. We do not specify anything in the method parameter.

Syntax

import datetime datetime.datetime.now()

Example

Let's find out the current time:

import datetime res = datetime.datetime.now() print(res)

The result of the executed code:

2025-12-31 16:52:06.433265

Example

Now let's derive the day, month, year, hour, minutes and seconds from the current time we received:

import datetime res = datetime.datetime.now() print(res.day) print(res.month) print(res.year) print(res.hour) print(res.minute) print(res.second)

The result of the executed code:

31 12 2025 16 53 28

See also

  • method datetime of module datetime,
    which creates a date and time object
  • method isleap of the calendar module,
    which determines a leap year
  • method date of module datetime,
    which creates a new object with a date
  • method today of module datetime,
    which returns the current date
  • method time of module datetime,
    which creates a 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