1

I have a string that contains a number of seconds outputted by a timer (please note that the string is updated every second):

5162

How can I parse this string to hour/minute/second format in javascript?

Cat Overlord
  • 163
  • 1
  • 4
  • 12

1 Answers1

2

You don't need to parse-just do some math.

Pseudocode:

sec=5162
hours = truncate(sec / 3600)
sec= sec modulo 3600
mins = truncate (sec/60)
sec = sec modulo 60

You don't mention what language you are using; in c, you can use sprintf to put all the pieces together into a string.

Jim Bob
  • 82
  • 1
  • 1
  • 5