简体   繁体   English

将日期从一种给定格式转换为另一种格式

[英]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. 如果我将第一个存储在变量中并尝试x.toISOString() ,则会引发错误。

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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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