zoukankan      html  css  js  c++  java
  • vue时间戳转化(10位/13位)

    13位:

    <template>
      <!-- time为时间戳 -->
      <div>{{time | formatDate}}</div>
      <!-- 结果为 2018-01-23 18:31:35 -->
    </template>
     
      export default {
        data() {
          return {
            time: 1516703495241//13位
          };
        },filters: {
          formatDate: function (value) {
            let date = new Date(value);
            let y = date.getFullYear();
            let MM = date.getMonth() + 1;
            MM = MM < 10 ? ('0' + MM) : MM;
            let d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            let m = date.getMinutes();
            m = m < 10 ? ('0' + m) : m;
            let s = date.getSeconds();
            s = s < 10 ? ('0' + s) : s;
            return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
          }
    

      十位:

    formatDate: function(value) {//10位时间戳转换
          let date = new Date(parseInt(value) * 1000);
          let y = date.getFullYear();
          let m = date.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          let d = date.getDate();
          d = d < 10 ? "0" + d : d;
          let h = date.getHours();
          h = h < 10 ? "0" + h : h;
          let minute = date.getMinutes();
          let second = date.getSeconds();
          minute = minute < 10 ? "0" + minute : minute;
          second = second < 10 ? "0" + second : second;
          return m + "月" + d + "日 " + h + ":" + minute + ":"+second;
     }
    

      

    集思广益,仅供学习,侵权即删!!
  • 相关阅读:
    HTTP协议入门
    TCP/IP的分层管理
    TCP与UDP
    如何处理某个Web页面的HTTP请求
    AGC005D ~K Perm Counting
    “玲珑杯” 线上赛Round #17 B 震惊,99%+的中国人都会算错的问题
    bzoj4455 [Zjoi2016]小星星
    AGC010F Tree Game
    AGC016E Poor Turkeys
    AGC003E Sequential operations on Sequence
  • 原文地址:https://www.cnblogs.com/hudunyu/p/13432070.html
Copyright © 2011-2022 走看看