Printing Time in Python
To work with time, you need to output it using the time method of the datetime module. The hour, minutes, seconds are passed to the method parameters:
res = datetime.time(12, 59, 59)
print(res.weekday()) # 12:59:59
By accessing the properties of the time method, you can also get hours, minutes, and seconds:
print(res.hour) # 12
print(res.minute) # 59
print(res.second) # 59
To get the full current date and time in the format year-month-day hour:minutes:seconds.milliseconds, you need to apply the datetime and now methods sequentially:
res = datetime.datetime.now()
print(res) # will display the current full date and time
Also, from this full date, its individual indicators can be derived by referring to the corresponding properties - day, month, year and so on.:
print(res.day)
print(res.month)
print(res.year)
print(res.hour)
print(res.minute)
print(res.second)
Print the current time to the console in the format hours:minutes:seconds.
Output the current time to the console in the format year-month-day hours:minutes:seconds.