Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript toISOString return incorrect date issue

Tags:

javascript

The toISOString method return incorrect date.

 // Input 
    var a = new Date("June 08, 2018");
    a.toISOString().slice(0, 10);

 // Output
    "2018-06-07"

// Expected output
   "2018-06-08"
like image 703
anonymous Avatar asked Dec 21 '25 17:12

anonymous


1 Answers

Use Z at the end of your date value. This will ignore the ISO timezone conversion and it will give you the value based on your local time.

var a = new Date("June 08, 2018 Z");
var res = a.toISOString().slice(0, 10);
console.log(res);
like image 101
Ankit Agarwal Avatar answered Dec 23 '25 07:12

Ankit Agarwal