2

What would be the best way to get a python time object form milliseconds int? For example:

ms = 2588832
datetime.timedelta(seconds = ?)

The answer I want to get is "00:43:08"

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    http://stackoverflow.com/questions/748491/how-do-i-create-a-datetime-in-python-from-milliseconds duplicate – FirebladeDan Jul 28 '15 at 19:36
  • @FirebladeDan: That answer shows how to create a timestamp, not a timedelta. – Kevin Jul 28 '15 at 19:38
  • @Kevin - If you take the freeway home vs the frontage road still gets you home right? Same thing ultimately he wanted datetime. Both suffice – FirebladeDan Jul 28 '15 at 19:49
  • @FirebladeDan: No. The other answer is flat wrong because it incorrectly assumes floating point division is accurate (it isn't). – Kevin Jul 28 '15 at 19:50
  • I'm not going to argue for some other person's post. It was selected as the best answer. – FirebladeDan Jul 28 '15 at 19:51
  • @FirebladeDan: The correct answer is a variation of my answer plus some datetime arithmetic which OP didn't ask for. I fail to see how that is a duplicate of this. – Kevin Jul 28 '15 at 19:53

1 Answers1

4

You can create timedeltas directly from milliseconds:

datetime.timedelta(milliseconds=2588832)
Kevin
  • 28,963
  • 9
  • 62
  • 81