Today() function of datetime.date class in Python

Function Name:

today

Function Signature:

@classmethod today()

Return Value:

Returns the current local date.

Function Overview:

  • The method today() of the date class, returns the current local date. By local it means the system and its current time settings used. 
  • To construct the date, the date.today() function makes use of the current time.
  • Note that the date.today()is a class method. Hence, it can be called using the class name date itself, rather using an instance of date class.

   

Example:

import datetime

import time

 

# Using date.today()

todaysDate = datetime.date.today();

print("Today's date - Using date class:%s"%todaysDate);

 

# Using date.fromtimestamp()

todaysDate = datetime.date.fromtimestamp(time.time());

print("Today's date - Using time class:%s"%todaysDate);

 

Output:

Today's date - Using date class:2019-07-11

Today's date - Using time class:2019-07-11


Copyright 2024 © pythontic.com