Frage

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 :/

War es hilfreich?

Lösung

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).

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top