I. Replace string with date
VaR date = new date (date. parse (strtime. Replace (/-/g, "/"); // convert to data ();
Ii. Format encapsulation of dates by JavaScript
<Script language = "JavaScript" type = "text/JavaScript"> <! --
/**
* Extended Date: converts date to a string in the specified format.
* Month (M), Day (D), 12 hours (H), 24 hours (H), minute (M), second (s), Week (E), quarter (q) can use 1-2 placeholders
* Year (y) can use 1-4 placeholders, Millisecond (s) can only use 1 placeholder (1-3 digits)
* Eg:
* (New date (). pattern ("yyyy-mm-dd hh: mm: Ss. s") => 08:09:04. 423
* (New date (). pattern ("yyyy-mm-dd e hh: mm: SS") => 20:09:04
* (New date (). pattern ("yyyy-mm-dd EE hh: mm: SS") => 08:09:04 Tuesday
* (New date (). pattern ("yyyy-mm-dd EEE hh: mm: SS") => 08:09:04 Tuesday
* (New date (). pattern ("yyyy-m-d h: M: S. S") => 2006-7-2. 18
*/
Date. Prototype. pattern = function (FMT ){
VaR o = {
"M +": This. getmonth () + 1, // month
"D +": This. getdate (), // day
"H +": This. gethours () % 12 = 0? 12: This. gethours () % 12, // hour
"H +": This. gethours (), // hour
"M +": This. getminutes (), // minute
"S +": This. getseconds (), // second
"Q +": Math. Floor (this. getmonth () + 3)/3), // quarter
"S": This. getmilliseconds () // millisecond
};
VaR week = {
"0": "\ u65e5 ",
"1": "\ u4e00 ",
"2": "\ u4e8c ",
"3": "\ u4e09 ",
"4": "\ u56db ",
"5": "\ u4e94 ",
"6": "\ u516d"
};
If (/(Y +)/. Test (FMT )){
FMt = FMT. Replace (Regexp. $1, (this. getfullyear () + ""). substr (4-Regexp. $1. Length ));
}
If (/(E +)/. Test (FMT )){
FMt = FMT. Replace (Regexp. $1, (Regexp. $1. length> 1 )? (Regexp. $1. length> 2? "\ U661f \ u671f": "\ u5468"): "") + week [This. getday () + ""]);
}
For (var k in O ){
If (New Regexp ("(" + K + ")"). Test (FMT )){
FMt = FMT. Replace (Regexp. $1, (Regexp. $1. Length = 1 )? (O [k]): ("00" + O [k]). substr ("" + O [k]). Length )));
}
}
Return FMT;
}
VaR date = new date ();
Window. Alert (date. pattern ("yyyy-mm-dd hh: mm: SS "));
// --> </SCRIPT>