Search code examples
pythonreal-timeclocklow-level

Access Real Time on Computer


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


Solution

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