Home » Python » Python programs

Python program to print current hour, minute, second and microsecond

Here, we are going to learn how to print current hour, minute, second and microsecond in Python programming language? This is an example of datetime module in Python.
Submitted by IncludeHelp, on March 09, 2020

In the below example – we are implementing a python program to print current hour, minute, second and microsecond.

Steps:

  • Import the datetime class from datetime module
  • Create an object by calling the now() function of datetime class
  • Extract and print the current hour, minute, second and microsecond using the object of datetime.now().
# Python program to print current hour, 
# minute, second and microsecond

# importing the datetime class from 
# datetime module
from datetime import datetime

# creating object
obj_now = datetime.now()

# printing the current date and time
print("Current date & time: ", obj_now)

# extracting and printing the current
# hour, minute, second and microsecond
print("Current hour =", obj_now.hour)
print("Current minute =", obj_now.minute)
print("Current second =", obj_now.second)
print("Current microsecond =", obj_now.microsecond)

Output

Current date & time:  2020-03-09 08:52:48.262154
Current hour = 8
Current minute = 52
Current second = 48
Current microsecond = 262154






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.