bootstrap-table 显示日期?

新手上路,请多包涵

这个table 是根据后台返回的json 生成的数据(包括列)---$('#tableOnlineFlow').bootstrapTable(json);,请问怎么设置这个sale_date 显示的格式呢?

clipboard.png

阅读 9.3k
2 个回答

执行这个$('#tableOnlineFlow').bootstrapTable(json)之前把json处理一遍喽,不过这个一般都是后端来搞

这个Date返回的是1970年1月1日到现在的毫秒数,需要转换一下,可以执行下面的方法

 function jsonDateFormat(jsonDate) {
            //json日期格式转换为正常格式
            var jsonDateStr = jsonDate.toString();//此处用到toString()是为了让传入的值为字符串类型,目的是为了避免传入的数据类型不支持.replace()方法
            try {
                var k = parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10);
                if (k < 0) 
                    return null;

                var date = new Date(parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10));
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                var milliseconds = date.getMilliseconds();
                return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
            }
            catch (ex) {
                return "时间格式转换错误";
            }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进