Created
February 29, 2012 21:28
-
-
Save ricardodani/1944527 to your computer and use it in GitHub Desktop.
Return a `time` object with the given num of miliseconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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