前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >EasyUI 时间格式化「建议收藏」

EasyUI 时间格式化「建议收藏」

作者头像
全栈程序员站长
发布2022-08-26 21:44:00
5230
发布2022-08-26 21:44:00
举报

大家好,又见面了,我是你们的朋友全栈君。

方法1:

formatter:function(value,row,index){

var unixTimestamp = new Date(value);

return unixTimestamp.toLocaleString();

}

方法2:

formatter : function(value) {

var date = new Date(value);

var year = date.getFullYear().toString();

var month = (date.getMonth() + 1);

var day = date.getDate().toString();

var hour = date.getHours().toString();

var minutes = date.getMinutes().toString();

var seconds = date.getSeconds().toString();

if (month < 10) {

month = “0” + month;

}

if (day < 10) {

day = “0” + day;

}

if (hour < 10) {

hour = “0” + hour;

}

if (minutes < 10) {

minutes = “0” + minutes;

}

if (seconds < 10) {

seconds = “0” + seconds;

}

return year + “-” + month + “-” + day + ” ” + hour + “:” + minutes + “:” + seconds;

}

方法3:

formatter: formatDatebox

Date.prototype.format = function (format) {

var o = {

“M+”: this.getMonth() + 1, // month

“d+”: this.getDate(), // day

“h+”: this.getHours(), // hour

“m+”: this.getMinutes(), // minute

“s+”: this.getSeconds(), // second

“q+”: Math.floor((this.getMonth() + 3) / 3), // quarter

“S”: this.getMilliseconds() // millisecond

} ;

if (/(y+)/.test(format))

format = format.replace(RegExp.$1, (this.getFullYear() + “”)

.substr(4 – RegExp.$1.length));

for (var k in o)

if (new RegExp(“(” + k + “)”).test(format))

format = format.replace(RegExp.1, RegExp.1.length == 1 ? o[k] : (“00” + o[k]).substr((“” + o[k]).length));

return format;

};

function formatDatebox(value) {

if (value == null || value == ”) {

return ”;

}

var dt;

if (value instanceof Date) {

dt = value;

} else {

dt = new Date(value);

}

return dt.format(“yyyy-MM-dd”); //扩展的Date的format方法(上述插件实现)

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/145056.html原文链接:https://javaforall.cn

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022年5月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com