当前位置: 代码网 > it编程>编程语言>Javascript > Vue如何获取new Date().getTime()时间戳

Vue如何获取new Date().getTime()时间戳

2024年10月28日 Javascript 我要评论
vue获取new date().gettime() 时间戳在处理按钮显示的时候发现一个问题:vue 通过new date().gettime()获取时间戳返回的是13位数字,单位是毫秒;php后台ti

vue获取new date().gettime() 时间戳

在处理按钮显示的时候发现一个问题:

vue 通过new date().gettime()获取时间戳返回的是13位数字,单位是毫秒;

php后台time()获取的时间戳是10位数字,单位秒;

所以在判断比较时需要将time()*1000 转换为毫秒再去比较

<el-button v-if="new date(scope.row.end_time*1000).gettime()>new date().gettime()"  size="mini" icon="edit" @click="editgroupsaction(scope.$index, scope.row)">编辑</el-button>

vue动态获取当前时间

获取当前时间:

<template>
  <div id="home">
    <span class="deadline">截止{{ gettime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "home",
  data() {
    return {
      gettime: "", //当前时间
    };
  },
 
  methods: {
    gettime() {
    var _this = this;
      let yy = new date().getfullyear();
      var mm =
        new date().getmonth() > 9
          ? new date().getmonth() + 1
          : new date().getmonth() == 9
          ? new date().getmonth() + 1
          : '0' + (new date().getmonth() + 1);
      var dd = new date().getdate() < 10 ? '0' + new date().getdate() : new date().getdate();
      let hh = new date().gethours();
      let mf =
        new date().getminutes() < 10 ? '0' + new date().getminutes() : new date().getminutes();
      let ss =
        new date().getseconds() < 10 ? '0' + new date().getseconds() : new date().getseconds();
      _this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
    },
    currenttime() {
      setinterval(this.gettime, 1000);
    },
   
  },
  mounted() {
    this.currenttime();
  },
};
</script>
 
<style scoped>
</style>

获取当前日期:

<template>
  <div id="home">
    <span class="deadline">当前日期{{ sendtime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "home",
  data() {
    return {
      sendtime: "", //当前时间
    };
  },
  mounted() {
    this.format();
  },
  methods: {
      format() {
                    const nowdate = new date();
                    const date = {
                        year: nowdate.getfullyear(),
                        month: nowdate.getmonth() + 1,
                        date: nowdate.getdate(),
                    }
                    const newmonth = date.month > 9 ? date.month : '0' + date.month
                    const day = date.date > 9 ? date.date : '0' + date.date
                    this.sendtime = date.year + '.' + newmonth + '.' + day
 
                }, //获取当前时间
   
  },
};
</script>
 
<style scoped>
</style>

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com