Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current time with python [duplicate]

How do you get the current time in python? I have seen people get the date and time, but I only want the time as a string.

For example, if the current time was 8:30, the command should output: "8:30".

Also, how do you find what day of the week it is>

For example, if it is Tuesday hen the output should be: 2.

like image 987
Kromydas Avatar asked Oct 30 '25 16:10

Kromydas


1 Answers

from datetime import datetime

print(datetime.now().strftime("%H:%M"))

Will return this:

13:29

To get seconds too:

print(datetime.now().strftime("%H:%M:%S"))

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!