Javascript date formatting example
This article mainly introduces the javascript date formatting example. For more information, see
The Code is as follows:
/**
* Format the date
* @ Param {Object} The MS specifies the number of milliseconds for the global standard time between the date and midnight, January 1, January 1, 1970
* @ Return year-month-date hh: mm
*/
Util. parseToDate = functions (MS ){
Var date = (new Date (parseInt (MS )));
Return formatDate (date, "yyyy-MM-dd mm: hh ");
};
/**
* Format the date
* <Code>
* Yyyy ------- year
* MM --------- month
* Dd --------- day
* Hh --------- hour
* Mm --------- minute
* For example, Util. formatDate (new Date (), 'yyyy-MM-dd mm: hh ');
* Or Util. formateDate (new Date (), 'yyyy/MM/dd mm/hh ');
* </Code> * @ param {Date} date the Date object to be formatted
* @ Param {Object} style
* @ Return returns the formatted current time.
*/
Util. formatDate = function (date, style ){
Var y = date. 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 );
}