2015-10-25 16 views
0

我有一個日期格式:如何轉換其他格式的日期?

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

我的目標是轉換日期爲這種格式:

2015-10-19T00:00:00 

如何我能實現這個結果呢?

UPDATE

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

回答

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

如果您願意,您可以剪掉末端部分。 (時區部分,-04:00)

來源:Moment.js

0

Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale)是javascript日期對象的字符串表示,使用此功能.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()); 
+0

我申請你的解決方案,但沒有工作的結果是:週一至2015年10月19日和小時丟失 – Dillinger

+0

是youusing momentjs?分享一些代碼 – Diptox

+0

我已經更新了我的問題,.start的結果是Mon Oct 19 2015 00:00:00 GMT + 0200(ora legale Europa occidentale) – Dillinger