The task is to find the current local date and time.
Approach 1: Using now()
import datetime current_time = datetime.datetime.now() print("The current time at greenwich meridian is: ", current_time)
import datetime currTime = datetime.datetime.now() print( "The current date in the format dd/mm/yyyy is :") print(currTime.day,"-",currTime.month,"-",currTime.year) print("The current time in hour:minute:second:microsecond format is ") print(currTime.hour,":",currTime.minute,":",currTime.second,":", currTime.microsecond)
Approach 2: Using pytz
In approach 1 we have used now() function to get the current date and time. The attributes of now() function is showed in Program 2 i.e. day, month, year, hour, minutes, second and microsecond. In approach 2, we have used pytz to get the current date and time of a particular timezone. In our code we have retrieved the date and time in India.