-1

Date is coming as 00:00:07 but I want to show in UI as 0h 0m 0s.

Is there a way to show like this ? I tried split function working fine but don't want to use split is there any library available?

Priyanka
  • 370
  • 1
  • 6
  • 15

1 Answers1

1

If you do not want to use split then following way can be used

var s = "10:03:07"

parts = s.match(/(\d+)\:(\d+):(\d+)/)

console.log(parts[1] + 'h ' + parts[2] + 'm ' + parts[3] + 's')

or you can create a new Date (i.e. today's date) with that exact time

d.setHours(parts[1])
d.setMinutes(parts[2])
d.setSeconds(part[3])
alert(d)
Shlok Nangia
  • 2,355
  • 3
  • 16
  • 24