页面从数据库获取时间显示有误

xiaoxiao2021-02-28  62

1.在jsp页面时间显示为一串数字,不符合正常格式 1)可以添加taglib <%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt”%> 使用的时候需要导入包,jstl和standard这两个包 然后在显示时间的地方加入fmt标签,例如: <input type="text" id="date" value="<fmt:formatDate value="{row.addtime}" pattern="yyyy-MM-dd"/>"/> 2)在js文件里进行时间格式处理

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方法(上述插件实现) } 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() } 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; } 调用formatDatebox(time)函数即可
转载请注明原文地址: https://www.6miu.com/read-2621165.html

最新回复(0)