strftime

Convert python datetime to epoch with strftime

Convert python datetime to epoch with strftime Question: I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime.datetime(2012,04,01,0,0).strftime(‘%s’) ‘1333234800’ 1st of April 2012 UTC from epoch is 1333238400 but …

Total answers: 8

Use datetime.strftime() on years before 1900? ("require year >= 1900")

Use datetime.strftime() on years before 1900? ("require year >= 1900") Question: I used : utctime = datetime.datetime(1601,1,1) + datetime.timedelta(microseconds = tup[5]) last_visit_time = “Last visit time:”+ utctime.strftime(‘%Y-%m-%d %H:%M:%S’) But I have the time of 1601, so the error show: ValueError: year=1601 is before 1900; the datetime strftime() methods require year >= 1900 I used python2.7, …

Total answers: 4

Using %f with strftime() in Python to get microseconds

Using %f with strftime() in Python to get microseconds Question: I’m trying to use strftime() to microsecond precision, which seems possible using %f (as stated here). However when I try the following code: import time import strftime from time print strftime(“%H:%M:%S.%f”) …I get the hour, the minutes and the seconds, but %f prints as %f, …

Total answers: 8

Display the date, like "May 5th", using pythons strftime?

Display the date, like "May 5th", using pythons strftime? Question: Possible Duplicate: Python: Date Ordinal Output? In Python time.strftime can produce output like “Thursday May 05” easily enough, but I would like to generate a string like “Thursday May 5th” (notice the additional “th” on the date). What is the best way to do this? …

Total answers: 5