2013-06-11 23 views
0

我有這個日期在這裏2013/06/10,它來自數據庫,並設置在一個變量稱爲日期。Javascript ...添加一天到目前爲止,並更改格式

我做這個加有一天這個日期..

var endDate = new Date(date); 
endDate.setDate(endDate.getDate() + 1); 

,現在我試圖改變格式YYYY/MM/DD

var finalEndDate = endDate.toString('yyyy/MM/dd'); 
alert(finalEndDate); 

但這返回

2013年6月11日東部標準時間等

我該如何解決這個問題?

+0

如果您使用的是jQuery,請考慮使用此插件:http://www.datejs.com/ – Learner

+0

endDate.toString('yyyy,MMMM,dddd') – Supplement

+4

http://stackoverflow.com/q/的重複項1056728 /。簡而言之,['Date'的'.toString()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)不接受參數。您需要使用'getMonth()'等手動格式化它,或者找到一個庫來格式化超出'toString()','toLocaleString()'等的日期。[Moment.js](http:// momentjs .com /)是一個普遍的建議,仍處於積極的發展階段。 –

回答

3

據我所知,toString沒有任何參數。雖然構建你的格式很容易。

var finalEndDate = endDate.getFullYear() + '/' + (endDate.getMonth() + 1) + '/' + endDate.getDate(); 

several getter methods date對象的每個部件,以幫助您構建幾乎任何格式。

相關問題