문제

currently I am attempting to access the OS clock using python.

Is there a sort of way I can access the clock value at this exact time and get a string that returns back lets say 12:00:00am PST or just the time? The timezone is a plus :)

I have currently done this time.clock() but nothing is giving me values back :/

도움이 되었습니까?

해결책

import time

print time.strftime('%I:%M:%S %p %Z')

For me, prints 12:21:51 PM EDT

Edit: Just want to clarify the place holders.

%I = Hour (12-hour clock) as a decimal number [01,12].
%M = Minute as a decimal number [00,59].
%S = Second as a decimal number [00,61].
%p = Locale’s equivalent of either AM or PM.
%Z = Time zone name (no characters if no time zone exists).

다른 팁

time.ctime() will do the job. time.time() will give you the time in seconds, just brows through the module time

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top