• Layui 时间转换时间戳


      我比较喜欢用Layui,当然也遇到一些坑!例如:绑定时间的时候是那种

     是这种13位数据的日期,如果不经过转换是不能正常显示的,当然这是我遇到的问题不知道你们有没有遇到,后来我也是经过了解才知道怎么回事!

    在表格里调用下列方法就解决了

    上解决方案:

     1  //layui 后台查询出来的时间绑定 时间戳转换 后台返回来的数据都要经过时间戳处理否则显示10或13位数字
     2                 function Format(datetime) {
     3                     debugger;
     4                     if (datetime != "") {
     5                         var date = new Date(parseInt(datetime.replace("/Date(", "").replace(")/", ""), 10));
     6                         //月份为0-11所以+1,月份小于10补个0
     7                         if (date != "") {
     8                             var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
     9                             var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    10                             var time = date.getFullYear() + "-" + month + "-" + currentDate;
    11                             if (time == "1-01-01") {
    12                                 return time = "";
    13                             }
    14                             else {
    15                                 return time;
    16                             }
    17                         }
    18                     }
    19                     else {
    20                         return "";
    21                     }
    22                 }
    View Code

    注意:在数据库字段为空的时候会返回“1-01-01”,必须判断然后给返回“”,页面才会不显示

    经过转换后的效果图:

      希望能帮助到喜欢用这个ui框架的小伙伴,还有不懂的可以在下方留言哦!当然解决方案还有很多我觉得这个是最适合我自己的,我也是个菜鸟有写的不好的地方也欢迎大家指出及时改正!

  • 相关阅读:
    Win10 64bit 下 Oracle 11g的安装
    删除服务列表中的任意服务 services.msc
    centos7修改docker镜像源的方法
    Docker零基础
    CentOS 查看日志命令
    mac 修改默认python,pip,为python3,pip3
    多次调用摄像头,需要考虑渲染问题
    Ant Designer Vue 中 layout 样式类名丢失
    Windows10 右键假死卡住转圈。
    mac 安装yarn
  • 原文地址:https://www.cnblogs.com/liuchunlin/p/11601626.html
Copyright © 2020-2023  润新知