简体   繁体   中英

converting date from one given format to another

I have date in this format ,

Tue Sep 04 2018 05:30:00 GMT 0530 (India Standard Time).

I need to convert it to this format

2018-12-16T00:00:00.000Z

If i store the first one in a variable and try x.toISOString() , it throws an error.

What should be the correct method to get this done ?

 function myFunction() { var d = new Date(); var n = d.toISOString(); document.getElementById("date").innerHTML = n; } 
 <button onclick="myFunction()"> Date in ISO</button> <div id="date"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM