//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