- /**
- * 格式化日期
- * @param {Object} ms 表示指定日期与 1970 年 1 月 1 日午夜间全球标准时间 的毫秒数
- * @return year-month-date hh:mm
- */
- Util.parseToDate = function(ms){
- var date = (new Date(parseInt(ms)));
- return formatDate(date,"yyyy-MM-dd mm:hh");
- };
- /**
- * 格式化日期
- * <code>
- * yyyy-------年
- * MM---------月
- * dd---------日
- * hh---------时
- * mm---------分
- * 如:Util.formatDate(new Date() , 'yyyy-MM-dd mm:hh');
- * or Util.formateDate(new Date(), 'yyyy/MM/dd mm/hh');
- * </code> * @param {Date}date 需要格式化的日期对象
- * @param {Object} style 样式
- * @return 返回格式化后的当前时间
- */
- 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);
- }
- //该片段来自于http://www.codesnippet.cn/detail/281120137560.html
来源: http://www.codesnippet.cn/detail/281120137560.html