這是我需要做的。JavaScript日期到字符串
取得日期,轉換爲字符串並傳遞給第三方實用程序。 當我通過它時,庫中的響應將以字符串格式存儲日期。所以,我需要將日期轉換爲字符串如20110506105524(YYYYMMDDHHMMSS)
function printDate() {
var temp = new Date();
var dateStr = temp.getFullYear().toString() +
temp.getMonth().toString() +
temp.getDate().toString() +
temp.getHours().toString() +
temp.getMinutes().toString() +
temp.getSeconds().toString();
debug (dateStr);
}
的問題上面是對於1-9個月,它打印一個數字。我怎樣才能改變它打印月,日正好2位數...
有你看着這個前一個:http://stackoverflow.com/questions/610406/javascript-printf-string-format – Liv 2011-05-06 16:07:24
作爲參考,這裏是一個明確的來源: [Javascript日期對象](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date) – 2012-12-19 16:41:25