-6

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

jsetting32
  • 1,632
  • 2
  • 20
  • 45

2 Answers2

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

Peter Foti
  • 5,526
  • 6
  • 34
  • 47
1

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

Martin
  • 493
  • 6
  • 16