Generally, the format of a date object obtained from the server (such as C # Code) may be 2014-04-04T13: 04: 46.187. When displaying the date object to the user, you may only need to display the date part, for example: many articles on JavaScript Date formatting in April 4, 2014 will directly convert the Date string into a JavaScript Date object, such as: new Date ("2014-04-04T13: 04: 46.187 ") // The system may prompt Invalid Date new Date ("April 04, 2014") // The system may prompt that Invalid Date has been tested. For the same string, the system prompts Invalid Date during conversion on the company's computer, on the home computer again. Is it because it is related to the computer system environment? To be considered. Generally, there are only a few types of date formats. Why not use regular expressions? Start by thinking about it. The regular expression for date matching is as follows (Chinese supported):/^ ([0-9] {4 })[-/\. year] ([0-1]? [0-9] {1}) [-/\. month] ([0-3]? [0-9] {1}) [Day]?.? ([0-2]? [0-9] (: [0-6] [0-9]) {2 })? /If you input the previous date format, the result may be as follows. Some people may wonder why there are so many date groups? Useful later: the complete code is attached: copy the code function getDateStr (value, formatStr) {formatStr = formatStr | "yyyy-MM-dd "; // default format: var dateReg =/^ ([0-9] {4 })[-/\. year] ([0-1]? [0-9] {1}) [-/\. month] ([0-3]? [0-9] {1}) [Day]?.? ([0-2]? [0-9] (: [0-6] [0-9]) {2 })? /; Var arr = dateReg.exe c (value); if (arr & arr [0]) {if (formatStr) {var subReg =/y + (.) M + (.) d + (.)? /I; var subArr = subReg.exe c (formatStr); if (subArr) {var resStr = arr [1] + subArr [1]; resStr + = arr [2] + subArr [2]; resStr + = arr [3] + (subArr [3] | ""); return resStr ;}} return arr [0];} return "";} copy the Code call: var a1 = getDateStr ("21:36:01", "yyyy MM dd ") // April 17, 2014 var a2 = getDateStr ("2014-4-17T21: 36: 01") // default format Note: getDateStr does not support directly passing a javascript Date object parameter, but it is easy to expand, perform the value before conversion. And then call the javascript method in Date. I will not talk about it here.