最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue如何獲取new Date().getTime()時(shí)間戳

 更新時(shí)間:2024年10月16日 08:48:07   作者:qianer0_0  
在Web開發(fā)中,前端使用Vue.js獲取的是毫秒級(jí)時(shí)間戳,而PHP后端則是秒級(jí)時(shí)間戳,處理此類問題時(shí),需要將PHP的時(shí)間戳乘以1000轉(zhuǎn)換為毫秒級(jí),以保證數(shù)據(jù)的一致性和正確的邏輯判斷

vue獲取new Date().getTime() 時(shí)間戳

在處理按鈕顯示的時(shí)候發(fā)現(xiàn)一個(gè)問題:

vue 通過new Date().getTime()獲取時(shí)間戳返回的是13位數(shù)字,單位是毫秒;

php后臺(tái)time()獲取的時(shí)間戳是10位數(shù)字,單位秒;

所以在判斷比較時(shí)需要將time()*1000 轉(zhuǎn)換為毫秒再去比較

<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動(dòng)態(tài)獲取當(dāng)前時(shí)間

獲取當(dāng)前時(shí)間:

<template>
  <div id="home">
    <span class="deadline">截止{{ gettime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      gettime: "", //當(dāng)前時(shí)間
    };
  },
 
  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>

獲取當(dāng)前日期:

<template>
  <div id="home">
    <span class="deadline">當(dāng)前日期{{ sendTime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      sendTime: "", //當(dāng)前時(shí)間
    };
  },
  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
 
                }, //獲取當(dāng)前時(shí)間
   
  },
};
</script>
 
<style scoped>
</style>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vscode中vue-cli項(xiàng)目es-lint的配置方法

    vscode中vue-cli項(xiàng)目es-lint的配置方法

    本文主要介紹vscode中 vue項(xiàng)目es-lint的配置方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的的朋友參考下吧
    2018-07-07
  • vue3使用富文本編輯器Editor.js的簡單方法

    vue3使用富文本編輯器Editor.js的簡單方法

    Editor.js是一個(gè)用于構(gòu)建具有完全可定制化塊結(jié)構(gòu)的現(xiàn)代編輯器的開源庫,它提供了一個(gè)簡潔、可擴(kuò)展和易于使用的接口,使開發(fā)人員能夠創(chuàng)建擁有豐富內(nèi)容和互動(dòng)性的編輯器,這篇文章主要給大家介紹了關(guān)于vue3使用富文本編輯器Editor.js的簡單方法,需要的朋友可以參考下
    2024-04-04
  • Vue中的event對象介紹

    Vue中的event對象介紹

    這篇文章介紹了Vue中的event對象,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • 詳解Vue.js搭建路由報(bào)錯(cuò) router.map is not a function

    詳解Vue.js搭建路由報(bào)錯(cuò) router.map is not a function

    這篇文章主要介紹了詳解Vue.js搭建路由報(bào)錯(cuò) router.map is not a function,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-06-06
  • vue版日歷組件的實(shí)現(xiàn)方法

    vue版日歷組件的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了vue版日歷組件的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue中如何給el-table-column添加指定列的點(diǎn)擊事件

    vue中如何給el-table-column添加指定列的點(diǎn)擊事件

    elementui中提供了點(diǎn)擊行處理事件,下面這篇文章主要給大家介紹了關(guān)于vue中如何給el-table-column添加指定列的點(diǎn)擊事件,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • Vue中的同步和異步使用詳解

    Vue中的同步和異步使用詳解

    這篇文章主要介紹了Vue中的同步和異步使用方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-08-08
  • vue keep-alive中的生命周期解讀

    vue keep-alive中的生命周期解讀

    這篇文章主要介紹了vue keep-alive中的生命周期,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue終極性能優(yōu)化方案(解決首頁加載慢問題)

    vue終極性能優(yōu)化方案(解決首頁加載慢問題)

    最近在做項(xiàng)目中前端采用Vue技術(shù),發(fā)現(xiàn)首頁加載速度非常之慢,下面這篇文章主要給大家介紹了關(guān)于vue終極性能優(yōu)化方案,主要解決首頁加載慢問題,需要的朋友可以參考下
    2022-02-02
  • watch里面的deep和immediate作用及說明

    watch里面的deep和immediate作用及說明

    這篇文章主要介紹了watch里面的deep和immediate作用及說明,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08

最新評(píng)論

扶余县| 漠河县| 石家庄市| 河南省| 武强县| 冕宁县| 益阳市| 乐山市| 碌曲县| 林州市| 得荣县| 沙雅县| 锡林郭勒盟| 潞城市| 无为县| 夏河县| 农安县| 尉犁县| 营口市| 贵州省| 新密市| 普宁市| 新沂市| 叙永县| 长治县| 黄骅市| 佛山市| 阿勒泰市| 定安县| 安吉县| 玉屏| 剑河县| 鄂尔多斯市| 高州市| 江津市| 专栏| 大兴区| 米泉市| 长沙市| 衡南县| 莲花县|