-2

I have used following to get number of minutes by passing Milliseconds

def returnTimeString(miliSec):
    returnVal = "%d" % (  ((miliSec / 1000) / 60) )
    if returnVal == '0':
        returnVal = 'N/A'
    return returnVal

But I want different way then this to fetch number of minutes by passing Milliseconds

O.T.
  • 26
  • 1
  • 1
  • 11

3 Answers3

2

here is what you need

minutes=float(miliSec/float(1000*60))%60.

simple and elegant

Python Pro
  • 39
  • 2
0

milliseconds to minutes

y = miliSec / 1000
y /= 60
minutes = y % 60

Oneliner

minutes=(miliSec/(1000*60))%60

Final result:

def returnTimeString(miliSec):
    minutes=(miliSec/(1000*60))%60
    return "%d" % (minutes) if minutes else 'N/A'
levi
  • 22,001
  • 7
  • 73
  • 74
-1

Here is another solution based on this post that gives you the conversion from milliseconds to seconds, minutes, and days.

def millitosec(milliseconds):
   x = milliseconds / 1000 
   seconds = x % 60
   x /= 60
   minutes = x % 60
   x /= 60
   hours = x % 24
   x /= 24
   days = x
   return seconds, minutes, hours, days
Community
  • 1
  • 1
Raja Sattiraju
  • 1,262
  • 1
  • 20
  • 42
  • Please don't post link only answers to other Stack Overflow questions. Instead, vote/flag to close as duplicate, or, if the question is not a duplicate, *tailor the answer to this specific question.* – Blue Aug 11 '16 at 08:15
  • It was valid Question, i was expecting different solution for my result – O.T. Aug 12 '16 at 04:31