2014-07-17 17 views
-2

我想將日期轉換爲yyyy-mm - dd這個格式。這裏是我的代碼。任何人都可以告訴我該怎麼做?代碼如何將日期轉換爲yyyy-mm-dd這種格式使用javascript?

var curr_date = new Date(date - i*86400000); 

輸出來了這樣

星期四2014年7月17日10時37分44秒GMT + 0530(印度標準時間)

但我需要像year-mm-dd這樣的輸出。

我也在努力爲這一年-MM-DD。這是工作的罰款。

var date = new Date(); 
var date_format =(date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate()); 

,但我想

var curr_date = new Date(date - i*86400000); 

轉換爲YYYY-MM - DD 如何追加VAR DATE_FORMAT和VAR curr_date

+0

在這裏,我將當前日期遞減到7天的一天。那麼我用「var curr_date = new Date(date - i * 86400000);」我希望這些7天的日期應該是這樣的yyyy-mm-dd。 – Sujitha

+0

「如何添加var date_format和var curr_date」我不知道你在說什麼,你想要做什麼? –

+0

嗨,大家好,我得到了解決方案。謝謝你的建議 – Sujitha

回答

0

使用FormatDate
$ .datepicker.formatDate(」 yyyy-mm-dd',new Date(date - i * 86400000));

Reference Jquery UI:

+0

需要jQuery和jQuery UI? – sharf

+0

JqueryUI更新了答案 –

0

這將這樣的伎倆。

var date = new Date(); 
var d = new Date(date - i*86400000); 
var curr_date = d.getDate(); 
var curr_month = d.getMonth() + 1; //Months are zero based 
var curr_year = d.getFullYear(); 
var date_format = curr_year + "-" + curr_month + "-" + curr_date; 
相關問題