Python Get Current Time In Hours Minutes Seconds

Python

Nicesnippets

401

02-10-2021


Hello Friends,

Now let's see example of how to get current time in python. I am going to show you python get current time in hours minitus and seconds. We will learn get current time in python.

The datetime module is supplies classes for manipulating dates and times. This article will give you example of get current hours, minitus and seconds in python.

Here I will give two example for how to get current time in python. I am use datetime and time module to get current hour, minute, seconds. So let's see the below example:

Example 1


import time

// get current time in hour, minute, seconds

currentTime = time.strftime("%H:%M:%S")

print(currentTime)

Output:

16:06:41

Example 2

from datetime import datetime

// get current date and time

currentTimeDate = datetime.now()

// get only time

currentTime = currentTimeDate.strftime('%H:%M:%S')

print(currentTime)

Output:

16:06:41

It will help you....