这周工作中,写了几个前端界面,页面中有个表格列字段是时间类型的,但是后端传递过来的时间是时间戳,所以需要在前端将其转换展示。
记录一下格式化日期代码,以后再遇见类似功能直接复制黏贴即可(其实是为了多点时间摸鱼):
(1) 日期格式化代码
/**
* 日期格式化函数<br/>
* 调用格式:需要使用日期对象调用
* <p> new Date().Format("yyyy/MM/dd HH:mm:ss"); </p>
* @param fmt 日期格式
* @returns {*} 返回格式化后的日期
* @constructor
*/
Date.prototype.Format = function (fmt) {
var object = {
"M+": this.getMonth() + 1, // 月
"d+": this.getDate(), // 日
"H+": this.getHours(), // 时
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((