Date-Time Module in Python
- Naveen
- 0
The data-time is a built-in module supplies classes for manipulating dates and times.
datetime.now
use the now() method to access the current date and time.
Date class in datetime module
We can represent the data object using the data class
Syntax to create a data object
datetime.date(year, month, day)
date.today()
it will return the current local date.
Time class in datetime module
To work only with time, we can use the time class.
Syntax to create a time object
datetime.time(hour, minute, second, microsecond, tzinfo, *, fold)
The arguments should be in the following range:
- 0 <= hour < 24
- 0 <= minute < 60
- 0 <= second < 60
- 0 <= microsecond < 1000000
- Fold in [0, 1]
- tzinfo is the timezone information.
If we pass an argument outside of given ranges, ValueError is raised.
datetime.now()
Use datetime.now() to return the local time.
Popular Posts
Spread the knowledge