cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to get the current time in Python?

Kaniz
Community Manager
Community Manager
 
3 REPLIES 3

Kaniz
Community Manager
Community Manager

from datetime import datetime

now = datetime.now()

current_time = now.strftime("%H:%M:%S")

print("Current Time =", current_time)

I'd suggest using datetime.utcnow() to avoid any issues with local times, especially if it's going into a library which needs unit testing.

Kaniz
Community Manager
Community Manager

Thank you @Darren Fullerโ€‹ 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.