bootstrap中时间显示格式问题

来源:互联网 发布:算法概论注释版pdf 编辑:程序博客网 时间:2024/06/05 03:58
整理一下bootstrap中的时间显示的格式问题的几种方式:
  • 数据格式显示方法一:

{name:'starttime',index:'starttime', width:160,edittype:"date", unformat: pickDate,editrules:{required:true},},
//enable datepickerfunction pickDate( cellvalue, options, cell ) {setTimeout(function(){$(cell) .find('input[type=text]').datepicker({format:'yyyy-MM-dd HH:mm:ss' , autoclose:true}); }, 0);}


在此处引用pickDate方法,将返回的毫秒值转换成相应的yyyy-MM-dd HH:mm:ss 格式显示在页面上

  • 数据格式显示方法二:

{name:'starttime',index:'starttime', width:160,edittype:"date", formatter:resultFormatter,,editrules:{required:true},},
  function getzf(num){             if(parseInt(num) < 10){                 num = '0'+num;              }              return num;           }  
function resultFormatter(cellvalue, timestamp, rowObject){          var oDate = new Date(cellvalue),             oYear = oDate.getFullYear(),              oMonth = oDate.getMonth()+1,              oDay = oDate.getDate(),              oHour = oDate.getHours(),              oMin = oDate.getMinutes(),              oSen = oDate.getSeconds(),              oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间              return oTime;  }


这是将传递回来的毫秒值通过计算并且拼接成固定格式返回给页面

目前我用的是这两种方式展示时间,其他的会遇到之后会逐步添加至此。

  • 数据中的根据条件筛选问题
{name:'starttime',index:'starttime', width:160,edittype:"date", sortable:true,searchoptions:{sopt:['lt','gt'],searchhidden : true,
dataInit : function (elem) {$(elem).datepicker({format:"yyyy-mm-dd", autoclose:true,editable: false})}}
};

标红的部分是设置搜索的格式,这个时候引入的js是<script src="${contextPath }/assets/js/date-time/bootstrap-datepicker.min.js"></script>

其他的搜索功能例如:{name:'content',index:'content', editable: true,hidden:true,search: true,editrules:{edithidden:true},edittype:"text",sortable:false,
formoptions:{elmsuffix:"<i style='color:red'>*</i>"},editoptions:{size:"20",maxlength:"30"},stype:"text",searchoptions:{searchhidden:true}},

{name:'lineid',index:'lineid', width:90, sortable:false,editable: true,edittype:"select",formatter:lineResult,
editoptions:{value:":请选择;" + getLine()},stype:"select",searchoptions:{value:":请选择;" + getLine()}},

{name:'linetype',index:'linetype', width:60, sortable:false,editable: true,edittype:"select",editrules:{required:true},formatter:linetypeResult,
editoptions:{value:":请选择;1:单;2:双"},stype:"select",searchoptions:{value:":请选择;1:单;2:双"}},


原创粉丝点击