/** String Conversion time */
Function strtodate (STR ){
str = str.replace(/-/g,"/");
var date = new Date(str );
}
Date. Prototype. format = function (Format ){
VaR o = {
"M +": This. getmonth () + 1, // month
"D +": This. getdate (), // day
"H +": This. gethours (), // hour
"M +": This. getminutes (), // minute
"S +": This. getseconds (), // second
"Q +": Math. Floor (this. getmonth () + 3)/3), // quarter
"S": This. getmilliseconds () // millisecond
}
If (/(Y +)/. Test (Format )){
Format = format. Replace (Regexp. $1, (this. getfullyear () + ""). substr (4-Regexp. $1. Length ));
}
For (var k in O ){
If (New Regexp ("(" + K + ")"). Test (Format )){
Format = format. Replace (Regexp. $1, Regexp. $1. Length = 1? O [k]: ("00" + O [k]). substr ("" + O [k]). Length ));
}
}
Return format;
}
// Usage
VaR now = new date ();
VaR nowstr = now. Format ("yyyy-mm-dd hh: mm: SS ");
// Method 2:
VaR testdate = new date ();
VaR teststr = testdate. Format ("mm-dd-yyyy HH mm min SS seconds ");
Alert (teststr );
// Example:
Alert (new date (). Format ("mm DD, YYYY "));
Alert (new date (). Format ("mm/DD/YYYY "));
Alert (new date (). Format ("yyyymmdd "));
Alert (new date (). Format ("yyyy-mm-dd hh: mm: SS "));
Time Format String Conversion time ()