How to use JavaScript Date Format Method

How to use the JavaScript Date Format method? This issue may be often seen in our daily study or work. I hope that you can give you a deep harvest through this issue. Below is the reference content brought by Xiaobian, let’s take a look!

// Extension to DATE, converts DATE into the String / / Month (M), Day (D), and Hours ( h), points (m), second (s), quarter (Q) can use 1-2 placeholders, // year (Y) can be used with 1-4 placeholders, milliseconds (s) can only be used 1 placeholder (a number of 1-3 bits) // example: // (“(” YYYY-MM-DD HH: mm: ss.s “) ==> 2006-07 -02 08: 09: 04.423 // (New Date ()). Format (“YYYY-MD H: M: SS”) ==> 2006-7-2 8: 9: 4.18 Date.Prototype.Format = Function FMT) {// Author: MEIZZ VAR O = {“M +”: this.getmonth () + 1, // “D +”: this.getdate (), // day “h +”: this.GetHours (), // hour “m +”: this.getminutes (), // 分 “s +”: this.getseconds (), // second “q +”: Math.Floor ((this.getmonth () + 3) / 3), // Quarter “S”: this.getmilliseconds () // millisecond}; if (/(y +) /. Test (FMT)) FMT = fmt.replace (regexp. $ 1, (this.Getfullyear () + “”) .substr (4 – regexp. $ 1.length); for (VAR K IN O) IF (“+ K +”) “). Test (FMT)) fmt = fmt.replace (regexp. $ 1, (regexp. $ 1.length == 1)? (o [k]): ( ( “00” + o [k]) substr (( “” + o [k]) length.))); return fmt;} new Date () Format (. “yyyy-mM-dd hh:. mm: ss “); //” 2016-01-19 15:53:24 “
  Method 2:  

2006-07 -02 08: 09: 04.423 * (New Date ()). Format (“YYY-MM-DD E HH: mm: SS”) ==> 2009-03-10 2 20:09:04 * (New Date ))). Format (“YYYY-MM-DD EE HH: MM: SS”) ==> 2009-03-10 Tuesday 08:09:04 * (New Date ()). Format (“YYYY-MM-DD EEE HH: mm: s “) ==> 2009-03-10 Tuesday 08:09:04 * (New Date ()). Format (” YYYY-MD H: M: SS “) ==> 2006-7-2 8: 9: 4.18 * / date.prototype.format = functioniON (FMT) {var o = {“m +”: this.getmonth () + 1, // “D +”: this.getdate (), // day “h +”: this.GetHours ()% 12 == 0? 12: this.GetHours ()% 12, // hour “h +”: this.GetHours (), // hour “m +”: this.getminutes (), // division “s +”: this.getSeconds () , // second “Q +”: Math.Floor ((this.getmonth () + 3) / 3), // quarter “s”: this.getmilliseConds () // millisecond}; var week = {“0”: “/ u65e5”, “1”: “/ u4e00”, “2”: “/ 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;} new Date () format (. “yyyy-mM-dd hh: mm: ss”); // “2016-01-19 03:59:41”
 Thank you for reading! After reading the above, do you know how to use the JavaScript Date Format method? I hope that the content of the article will help everyone. If you want to know more about the content, please pay attention to Tumi Yun Industry Information Channel.                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment