jmcall10
jmcall10

Reputation: 127

date totimestring replace hh:MM

I have this:

var myDate = new Date(r.date).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");

which returns the format in hh:MM:ss

However I only want the hh:MM formatwithout the seconds.

Any suggestions?

Upvotes: 1

Views: 852

Answers (1)

Federico klez Culloca
Federico klez Culloca

Reputation: 27119

Just take the last part of the regexp (the one that includes the seconds) out of the group, like this

var myDate = new Date(r.date).toTimeString().replace(/.*(\d{2}:\d{2}):\d{2}.*/, "$1");

so that the substitution only takes the first two numbers, a colon and another couple of numbers into account.

Upvotes: 1

Related Questions