Jquery converts the date and time type into the desired format.

Source: Internet
Author: User

Jquery converts the date and time type into the desired format.

1/** 2 * example: change the current time to xx, var date = new Date (); (to convert a given time to this format: var time = "2017-3-6 10:30:30" var date = new Date (time) 3 * var nowMs = date. getTime (); 4 * var currentTime = format ("MM dd, yyyy, HH, mm, ss seconds", nowMs ); 5*6 * @ param format the desired time format is "yyyy-MM-dd HH: mm: ss" (yyyy: indicates the year, MM: indicates the month, dd indicates the day, HH indicates the time, mm indicates the minute, ss indicates the second) 7 * @ param time milliseconds 8 * @ returns {* | string | void} 9 */10 var format = function (Format, time) {11 var t = new Date (time); 12 // Adding zero 13 var tf = function (I) {14 return (I <10? '0': '') + i15}; 16 return format. replace (/yyyy | MM | dd | HH | mm | ss/g, function (a) {17 switch (a) {18 case 'yyyy': 19 return tf (t. getFullYear (); 20 break; 21 case 'mm': 22 return tf (t. getMonth () + 1); 23 break; 24 case 'mm': 25 return tf (t. getMinutes (); 26 break; 27 case 'dd': 28 return tf (t. getDate (); 29 break; 30 case 'hh': 31 return tf (t. getHours (); 32 break; 33 case 'ss': 34 return tf (t. getSeconds (); 35 break; 36} 37}) 38}

 

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.