Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I would like to remove seconds and milliseconds from my date

For now, I post my date like this:

17:34:14.965

I would only have the hours and minutes. How to do ?

like image 328
Romain Boutinet Avatar asked Oct 16 '25 03:10

Romain Boutinet


2 Answers

you can do in this way

var date="17:34:14.965";

var splittedString=date.split(":");

date=splittedString.slice(0,-1).join(':');

reference split , slice, join

like image 92
Marco Moretti Avatar answered Oct 18 '25 05:10

Marco Moretti


Replace with a regular expression will do the job:

var dateString = '17:34:14.965'
console.log( dateString.replace(/:[^:]*$/,'') );
like image 21
RobG Avatar answered Oct 18 '25 03:10

RobG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!