欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

elementUI 时间格式化(一般方法)

程序员文章站 2022-04-28 17:44:34
1.html: 2.vue的methods 里面 ......

1.html:

...
<el-table-column prop="updatetime" label="更新时间" width="160" align="center" :formatter="dateformat"></el-table-column>
...

2.vue的methods 里面

//方法
methods: {
    //时间格式化
    dateformat:function(row,column){
        var t=new date(row.updatetime);//row 表示一行数据, updatetime 表示要格式化的字段名称
        return t.getfullyear()+"-"+(t.getmonth()+1)+"-"+t.getdate()+" "+t.gethours()+":"+t.getminutes()+":"+t.getseconds()+"."+t.getmilliseconds();
    },
  //时间格式化2
  dataformat2:function(row,column){
      var t=new date(row.updatetime);//row 表示一行数据, updatetime 表示要格式化的字段名称
      var year=t.getfullyear(),
          month=t.getmonth()+1,
          day=t.getdate(),
          hour=t.gethours(),
          min=t.getminutes(),
          sec=t.getseconds();
      var newtime=year+'-'+
          (month<10?'0'+month:month)+'-'+
          (day<10?'0'+day:day)+' '+
          (hour<10?'0'+hour:hour)+':'+
          (min<10?'0'+min:min)+':'+
          (sec<10?'0'+sec:sec);
      return newtime;
  },
},