I have a
datetime object. I want to print it as just number of seconds (i.e., 1 min 30.5 sec should print as 90.5 s). Can't seem to find a way to do it with
I think that for your situation you'd be better off using a datetime.timedelta object. It has a function that will do exactly what you want, datetime.timedelta.total_seconds().Answer2:
Datetimes are instants in time, unlike <em>durations</em> which are just numbers. The reason
strftime won't say "90.5s" is that, well, that is a duration and not a datetime.
Does your datetime object represent the instant that is 90.5 seconds past the epoch? If so, just get the epoch time in millis and divide by 1000, concat an "s" and you are good to go.
Also, for fun, see <a href="http://en.wikipedia.org/wiki/ISO_8601#Durations" rel="nofollow">http://en.wikipedia.org/wiki/ISO_8601#Durations</a>.