Skip to content

Instantly share code, notes, and snippets.

@ricardodani
Created February 29, 2012 21:28
Show Gist options
  • Save ricardodani/1944527 to your computer and use it in GitHub Desktop.
Save ricardodani/1944527 to your computer and use it in GitHub Desktop.
Return a `time` object with the given num of miliseconds.
from datetime import time
def time_ms(miliseconds=0):
'''Return a `time` object with the given num of miliseconds.'''
total_micros = miliseconds * 1000
microseconds = total_micros % 1000000
total_seconds = total_micros / 1000000
seconds = total_seconds % 60
total_minutes = total_seconds / 60
minutes = total_minutes % 60
total_hours = total_minutes / 60
hours = total_hours % 24
return time(
hour = hours,
minute = minutes,
second = seconds,
microsecond = microseconds
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment