简体   繁体   English

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

[英]How to convert a date in other format?

I've a date with this format: 我有个这样的约会:

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

My goal is convert a date into this format: 我的目标是将日期转换为以下格式:

2015-10-19T00:00:00

How I can achieve this result? 我怎样才能达到这个结果?

UPDATE 更新

var currDateEnd = $('#calendar').fullCalendar('getView').start;
                        currDateEnd.toISOString();
                        console.log("currDateEnd iso => ", currDateEnd.toDate().toDateString());
moment().format();  // results in something like : 2015-10-25T13:09:29-04:00

You could just snip off the end part if you wanted. 如果需要,可以只剪掉末端部分。 (The timezone part, -04:00) (时区,-04:00)

Source: Moment.js 资料来源: Moment.js

this Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale) is the String representation of Javascript Date Object , so use this function .toISOString(); Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale)是JavaScript日期对象的字符串表示形式,因此请使用此函数.toISOString(); like this 像这样

Demo 演示版

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

try this 尝试这个

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

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

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