如何转换其他格式的日期?

时间:2015-10-25 17:06:13

标签: javascript fullcalendar momentjs

我有这种格式的日期:

Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale)

我的目标是将日期转换为以下格式:

2015-10-19T00:00:00

我如何才能达到这个结果?

更新

var currDateEnd = $('#calendar').fullCalendar('getView').start;
                        currDateEnd.toISOString();
                        console.log("currDateEnd iso => ", currDateEnd.toDate().toDateString());

2 个答案:

答案 0 :(得分:1)

moment().format();  // results in something like : 2015-10-25T13:09:29-04:00

如果你愿意的话,你可以剪掉最后一部分。 (时区部分,-04:00)

来源:Moment.js

答案 1 :(得分:0)

这个Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale)是Javascript Date Object的String表示,所以像这样使用这个函数.toISOString();

Demo

var d = new Date();
$(".yo").append("The String of the object -> "+d.toString()+"<br>");
$(".yo").append("What you want -> "+d.toISOString());

试试这个

var currDateEnd = $('#calendar').fullCalendar('getView').start;
console.log("currDateEnd iso => ", currDateEnd.toDate().toISOString());
相关问题