JS converts a long date format to a standard date format

Source: Internet
Author: User

//extend the Format method for dateDate.prototype.format =function(format) {varo = {              "m+": This. GetMonth () + 1,              "D+": This. GetDate (),"H +": This. GetHours (),"m+": This. getminutes (),"S+": This. getseconds (),"q+": Math.floor (( This. GetMonth () + 3)/3),              "S": This. getmilliseconds ()}if(/(y+)/. Test (format)) {Format= Format.replace (Regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); }           for(varKincho) {if(NewRegExp ("(" + K + ")"). Test (format)) {format= Format.replace (regexp.$1, regexp.$1.length = = 1? O[k]: ("XX" + o[k]). substr ("" +O[k]) (length)); }          }          returnformat; }      /** * Convert Date object to date String * @param a Date Date Object * @param isfull is the full date data, * True if the format is "200 0-03-05 01:05:04 "* is false, formats such as" 2000-03-05 "* @return match the required date string*/        functiongetsmpformatdate (date, isfull) {varPattern = ""; if(Isfull = =true|| Isfull = =undefined) {Pattern= "Yyyy-mm-dd Hh:mm:ss"; } Else{pattern= "Yyyy-mm-dd"; }          returngetformatdate (date, pattern); }      /** * Convert the current Date object to a date string * @param a Date Date Object * @param isfull is the full date data, * True if the format is "2 000-03-05 01:05:04 "* is false, formats such as" 2000-03-05 "* @return match the required date string*/          functiongetsmpformatnowdate (isfull) {returnGetsmpformatdate (NewDate (), isfull); }      /** * Convert Long value to date String * @param l Long value * @param isfull is full date data, * True, format as "2000" -03-05 01:05:04 "* is false, format such as" 2000-03-05 "* @return match the required date string*/          functionGetsmpformatdatebylong (L, isfull) {returnGetsmpformatdate (NewDate (L), isfull); }      /** * Convert Long value to date String * @param l Long value * @param pattern format string, for example: Yyyy-mm-dd HH:MM:SS * @return Meet requirements The date string*/          functionGetformatdatebylong (l, pattern) {returnGetformatdate (NewDate (L), pattern); }      /** * Convert Date object to date String * @param l Long value * @param pattern format string, for example: YYYY-MM-DD HH:MM:SS * @return Compliant Date string*/        functiongetformatdate (date, pattern) {if(Date = =undefined) {Date=NewDate (); }          if(Pattern = =undefined) {Pattern= "Yyyy-mm-dd Hh:mm:ss"; }          returnDate.format (pattern); }  

Transferred from: http://yan578351314.iteye.com/blog/1275177

JS converts a long date format to a standard date format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.