Posts

Showing posts with the label datetime module

Python - datetime module

Image
The datetime module contains the following classes, which together comprise the majority of the functionality for working with dates and times: date time datetime date class To work with data, we’ll use the Date class defined in the DateTime module. To construct a Date object, let’s use the Date constructor. The Date constructor takes three parameters: Year, Month, and Day. date(year, month, day) For example, let's create a date: import datetime   date = datetime.date( 2024 , 1 , 1 ) print(date)       # 2024-01-01 The today() method is used to retrieve the current date. from datetime import date   today = date.today() print(today)       # 2023-12-31 print( "{}.{}.{}" .format(today.day, today.month, today.year)) # 31.12.2023 Using the properties day, month, year you can get the day, month and year respectively time class The time class takes care of dealing with time. With its constructor, a time object can be created: time([hour] [, min] [, sec] [, microsec]) The hour,