Date.prototype.Format =function(FMT) {varo = { "m+": This. GetMonth () + 1,//Month"D+": This. GetDate (),//Day"H +": This. GetHours (),//hours"m+": This. getminutes (),//points"S+": This. getseconds (),//seconds"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarterly"S": This. Getmilliseconds ()//milliseconds }; if(/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); for(varKincho)if(NewRegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +o[k])); returnFMT; } //called varDate =NewDate (). Format ("Yyyy-mm-dd hh:mm:ss");
2:
Public class Stringtodate {public staticvoidMain (string []args) {string myString= "2011-09-18 11:20:30"; Date mydate=NULL; DateFormat DF=dateformat.getdateinstance (); //set the time formatSimpleDateFormat myformdate =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); Try{mydate=Df.parse (myString); } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace (); }system.out.println (mydate);}} Results: Sun SEP00:00:00 CST 2011functionTodate (num) {//Fri Oct to 18:00:00 utc+0800num = num + "";//give the string a space after it varDate = ""; varmonth =NewArray (); month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["APR"] = 4; month["May"] = 5; month["Jan"] = 6; month["Jul"] = 7; Month["" "] = 8; month["SEP"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12; varWeek =NewArray (); week["Mon"] = "one"; week["Tue"] = "two"; week["Wed"] = "three"; week["Thu"] = "Four"; week["Fri"] = "five"; week["Sat"] = "six"; Week["Sun"] = "Day"; STR= Num.split ("");//array based on spacesDate = Str[5] + "-";//is to add a "-" to the back of 2008. //you can get the format you want by modifying it here.Date = date + month[str[1]] + "-" + str[2] + "" + str[3]; //date=date+ "Week" +week[str[0]]; returndate; }
JS Date conversion Fri Oct to 18:00:00 utc+0800 2008 to YYYY-MM-DD