Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  143] [ 4]  / answers: 1 / hits: 20375  / 7 Years ago, thu, november 2, 2017, 12:00:00

how can I remove the time after converting a date to ISO String?



var now = new Date();
console.log( now.toISOString() );


if the output is



2017-10-19T16:00:00.000Z


I just want it to be :



2017-10-19

More From » jquery

 Answers
85

There are actually many ways to do so:


1- Use Moment JS which gives you kind of flexibility in dealing with the issue


2- The simple way to do it in native JS is to use substring() function like that:


var date = new Date();
console.log(date.toISOString().substring(0,10));

The second way would be more effective if all you need is to remove the time part of the string and use the date only.


[#56039] Monday, October 30, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stephonkeandrer

Total Points: 392
Total Questions: 94
Total Answers: 100

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;