Data and Time in Python

Working with Date and Time in Python programming to get Computer's current date and time in different formats by using a standard Time 'time' library of Python programming language.

Program Getting Date and Time and Printing

Program

import time #importing Library for working with Time and Date.
localtime = time.localtime(time.time()) #getting and assigning to 'localtime'.
print("Local current time :", localtime) #and printing.
Output
Local current time : time.struct_time(tm_year=2023, tm_mon=10, tm_mday=6, tm_hour=15, tm_min=41, tm_sec=56, tm_wday=4, tm_yday=279, tm_isdst=0)

Program Printing Complete Current Date and Time

Program

import time #importing library for working with Date and Time.
localtime = time.asctime(time.localtime(time.time())) #getting Date and Time
print("Local current time :", localtime) #and assigning to 'lacaltime'.
Output
Local current time : Fri Oct 6 15:42:13 2023

Program Printing Complete Calendar

Program

import calendar #importing library for working with Calendar.
cal = calendar.month(2023, 10) #assigning Year and Month.
print("Here is the calendar:")
print(cal) #and printing All Calendar.
Output
Here is the calendar:
October 2023
Mo  Tu  We  Th  Fr  Sa  Su
                        1
2   3   4   5   6   7   8
9   10  11  12  13  14  15
16  17  18  19  20  21  22
23  24  25  26  27  28  29
30  31

Program Printing Current Date and Time
Program

import datetime #importing library for working with Date and Time.
dtatt = datetime.datetime.now() #assigning to 'dtatt'.
print("Current: ", dtatt) #and printing.
Output
Current: 2023-10-06 15:48:02.007439