JS Date conversion Fri Oct to 18:00:00 utc+0800 2008 conversion to YYYY-MM-DD

Source: Internet
Author: User
Tags dateformat

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

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.