So, using this website i have come up with the following code:
import time
print(time.strftime('%l:%M%p %Z on %b %d %Y'))
#' 1:36PM EDT on Oct 18, 2010'
print("time done")
time.sleep(5)
From the following sources: 1,2
For some reason though, this code doesn't work.
I'm trying to get the time to show similar to the comment, although if I could get the seconds in as well that would be good. I also tried this:
import time
print time.strftime("%l"+":"+"%M"+"%p"+ "%Z"+ "%b"+ "%d"+ "%Y")
#' 1:36PM EDT on Oct 18, 2010'
print("time done")
time.sleep(5)
but it doesn't work either.
EDIT: Error I get even from print(time.strftime('%l:%M:%S%p %Z on %b %d, %Y'))
:
AttributeError: '<invalid type>' object has no attribute 'strftime'
EDIT2: for those that don't believe me: !The error and code in CodeSkulptor] https://www.dropbox.com/s/joyxsod8yv899fm/THERE.png
I used python 3.3.3 and codeskulptor
All you forgot was a comma after
%d
:Adding in seconds means you want to insert
%S
somewhere:Note that CodeSkulptor does not support the
time
module very well. Code usingtime.strftime()
on CodeSkulptor will fail, but that is hardly a Python problem. Even a baseprint(time.strftime())
call fails.