Format of JS string to date:
// Format the date
Function dateformat (d ){
VaR da = new date (D. Replace (/-/g ,"/"));// This sentence is found on the internet, and many people make mistakes. The following/is followed by a space.
Return da. Format ("yyyy-mm-dd"); // execute the following date formatting Method
}
JS date formatting:
Date. Prototype. format = function (Format) // Author: meizz
{
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 d = "12:12:12 ";
VaR da = new date (D. Replace (/-/g ,"/"));
Alert (new date (). Format ("yyyy-mm-dd "));
Alert (new date ("January 12 2008"
11:12:30 "). Format (" yyyy-mm-dd hh: mm: SS "));
Convert JS string to date type
Convert a date string such as "10:18:30" to a date object:
VaRS = "09:41:30";VaRD =NewDate (date. parse (S. Replace (/-/g ,"/")));