Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  180] [ 5]  / answers: 1 / hits: 82328  / 15 Years ago, fri, may 29, 2009, 12:00:00

when using new Date,I get something like follows:



Fri May 29 2009 22:39:02 GMT+0800 (China Standard Time)



but what I want is xxxx-xx-xx xx:xx:xx formatted time string


More From » datetime

 Answers
18

Although it doesn't pad to two characters in some of the cases, it does what I expect you want



function getFormattedDate() {
var date = new Date();
var str = date.getFullYear() + - + (date.getMonth() + 1) + - + date.getDate() + + date.getHours() + : + date.getMinutes() + : + date.getSeconds();

return str;
}

[#99427] Tuesday, May 26, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karladaijahf

Total Points: 78
Total Questions: 123
Total Answers: 89

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;