JavaScript date formatting sample

Source: Internet
Author: User
Tags current time

  This article mainly introduces the JavaScript date format example, the need for friends can refer to the following

  Code as follows:/**    * format date    * @param {Object} MS represents the number of milliseconds between a specified date and the global standard Time between midnight January 1, 1970    * @return year-month-date hh:mm    */   util.parsetodate = function (ms) {        & nbsp   var date = (new Date (parseint (MS));           return formatdate (date, "Yyyy-mm-dd mm:hh");     };   /**    * format date    * <code>    * yyyy-------year    * MM---------Month    * DD---------Day    * hh---------   * mm---------minutes    * such as: Util.formatdate (New D Ate (), ' yyyy-mm-dd mm:hh ');    * or Util.formatedate (new Date (), ' yyyy/mm/dd mm/hh ');    * </code> * @param {date}date Date object that needs to be formatted    * @param {object} style style    * @return Returns the formatted current time    */   util.formatdate = function (date, style) {        var y = dat E.getfullyear ();          var M = "0" + (date.getmonth () + 1);          M = m.substring (m.length-2);         var d = "0" + date.getdate ();         d = d.substring (d.length-2);          var h = "0" + date.gethours ();          h = h.substring (h.length-2);          var m = "0" + date.getminutes ();          m = m.substring (m.length-2);          return style.replace (' yyyy ', y). Replace (' MM ', M). Replace (' DD ', D). Replace (' hh ', h). Replace (' mm ', m);    }   
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.