Date-Time Module in Python

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

Author

  • Naveen Pandey Data Scientist Machine Learning Engineer

    Naveen Pandey has more than 2 years of experience in data science and machine learning. He is an experienced Machine Learning Engineer with a strong background in data analysis, natural language processing, and machine learning. Holding a Bachelor of Science in Information Technology from Sikkim Manipal University, he excels in leveraging cutting-edge technologies such as Large Language Models (LLMs), TensorFlow, PyTorch, and Hugging Face to develop innovative solutions.

    View all posts
Spread the knowledge
 
  

Leave a Reply

Your email address will not be published. Required fields are marked *