zoukankan      html  css  js  c++  java
  • uniapp实时动态显示当前时间(时分秒)

    进入页面 实时动态显示当前时间(时分秒)

    <text class="punch-time">{{ clock | FormatTime }}</text>
    ------------------------------
     data() {
        return {
          clock: Date.parse(new Date()),
        };
      },
    
     mounted() {
        let _this = this;
        setInterval(function () {
          _this.clock = Date.parse(new Date());
        }, 1000);
      },
    
     filters: {
        FormatTime: function (val) {
          return getDate(val, "hour");//根据传参不同显示的时间类型也不同
        },
    },
    ---------------------------------
    //format.js:
    export function getDate(datetime, startType) {
      var date = new Date(datetime); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
      var year = date.getFullYear(),
        month = ("0" + (date.getMonth() + 1)).slice(-2),
        sdate = ("0" + date.getDate()).slice(-2),
        hour = ("0" + date.getHours()).slice(-2),
        minute = ("0" + date.getMinutes()).slice(-2),
        second = ("0" + date.getSeconds()).slice(-2);
      // 拼接
      // var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
      // 返回
      // return result;
      let resStr = "";
      if (startType === "year")
        resStr =
          year +
          "-" +
          month +
          "-" +
          sdate +
          " " +
          hour +
          ":" +
          minute +
          ":" +
          second;
      if (startType === "day") resStr = year + "-" + month + "-" + sdate;
      if (startType === "month") resStr = month + "-" + sdate;
      if (startType === "hour") resStr = hour + ":" + minute + ":" + second;
      return resStr;
    }
    
  • 相关阅读:
    Release COM Objects in AE
    图像相关系数
    Geoprocessor edit the featureclasses in memmory
    NetLogo AStar path finding
    IDL+C#三种调用方式
    Dictionary is not like a array
    C# DataGridView 禁止列排序
    工作总结
    (转)常见数据库设计(1)——字典数据
    碎碎念(3)
  • 原文地址:https://www.cnblogs.com/axingya/p/14982895.html
Copyright © 2011-2022 走看看