Javascript converts a Date string to a Date object.

Source: Internet
Author: User
Java code vars & quot; 2005-12-1509: 41: 30 & quot; vardnewDate (Date. parse (s. replace (/-/g, & quot;/& quot;); http://docs.jquery.com/ui/datepicker/$.datepicker.formatdate

Java code
Var s = "09:41:30 ";
Var d = new Date (Date. parse (s. replace (/-/g ,"/")));


Http://docs.jquery.com/ui/datepicker/developer.datepicker.formatdate
Can also be implemented


Java code
// A piece of code found on stackoverflow, date in js
Function printDate (){
Var temp = new Date ();
Var dateStr = padStr (temp. getFullYear () +
PadStr (1 + temp. getMonth () +
PadStr (temp. getDate () +
PadStr (temp. getHours () +
PadStr (temp. getMinutes () +
PadStr (temp. getSeconds ());
Debug (dateStr );
}
 
Function padStr (I ){
Return (I <10 )? "0" + I: "" + I;
}


Java code
// Data type conversion in json format
Var cloudNormFileDateFormat2 = {
FormatDate: function (date ){
Return dateStr = this. padStr (1900 + date. year) + "-" +
This. padStr (1 + date. month) + "-" +
This. padStr (date. date) + "" +
This. padStr (date. hours) + ":" +
This. padStr (date. minutes) + ":" +
This. padStr (date. seconds );
},
PadStr: function (I ){
Return (I <10 )? "0" + I: "" + I;
}
};

Author "caniggia1986"
 

Related Article

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.