Reputation: 179
I was wondering if I could use moment.js to convert an sql TIME (HH:mm:ss) to just HH:mm. Or maybe there is a simple JavaScript/jQuery solution to this?
Upvotes: 7
Views: 10400
Reputation: 1411
timeFormatting = (time) => {
return moment(time, 'HH:mm:ss').format('HH:mm')
}
Upvotes: 1
Reputation: 8141
Yes, you can:
moment('12:59:01', 'HH:mm:ss').format('HH:mm')
Or, if the format is consistent, you could just chop the last 3 chars:
'12:59:01'.slice(0, -3)
Upvotes: 15