Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Python to Print the Hour of Day

I am using the following code to get the time:

import time

time = time.asctime()

print(time)

I end up with the following result:

'Tue Feb 25 12:09:09 2014'

How can I get Python to print just the hour?

like image 308
user3352353 Avatar asked Feb 25 '14 17:02

user3352353


People also ask

How do I get the hour of the day in Python?

To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.

What does datetime now return Python?

The . datetime. now() method returns a new datetime object with the current local date and timestamp.


1 Answers

import time
print (time.strftime("%H"))
like image 137
pajton Avatar answered Oct 13 '22 06:10

pajton