欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

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

php后臺time()獲取的時間戳是10位數(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動態(tài)獲取當(dāng)前時間

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

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

總結(jié)

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

相關(guān)文章

  • vue中l(wèi)et that=this的作用及說明

    vue中l(wèi)et that=this的作用及說明

    這篇文章主要介紹了vue中l(wèi)et that=this的作用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue實(shí)現(xiàn)簡易計(jì)算器的4種方法舉例

    vue實(shí)現(xiàn)簡易計(jì)算器的4種方法舉例

    這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)簡易計(jì)算器的4種方法,文中通過代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue覺有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • vue計(jì)算屬性computed--getter和setter用法

    vue計(jì)算屬性computed--getter和setter用法

    這篇文章主要介紹了vue計(jì)算屬性computed--getter和setter用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Vue實(shí)現(xiàn)Google第三方登錄的示例代碼

    Vue實(shí)現(xiàn)Google第三方登錄的示例代碼

    本文記錄作者在vue項(xiàng)目中使用到Google第三方登錄,查詢到的資料文檔也不詳細(xì),故此把自己所遇到的坑及問題詳細(xì)的記錄下來。
    2021-07-07
  • vue中格式化時間過濾器代碼實(shí)例

    vue中格式化時間過濾器代碼實(shí)例

    這篇文章主要介紹了vue格式化時間過濾器,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 在Vue組件中使用 TypeScript的方法

    在Vue組件中使用 TypeScript的方法

    typescript不僅可以約束我們的編碼習(xí)慣,還能起到注釋的作用,當(dāng)我們看到一函數(shù)后我們立馬就能知道這個函數(shù)的用法。這篇文章主要介紹了在Vue組件中使用 TypeScript的方法,需要的朋友可以參考下
    2018-02-02
  • Vue 集成 storybook的方法

    Vue 集成 storybook的方法

    這篇文章主要介紹了Vue 集成 storybook的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • Vue組件封裝之input輸入框?qū)崙?zhàn)記錄

    Vue組件封裝之input輸入框?qū)崙?zhàn)記錄

    在vue中會將常用的組件進(jìn)行封裝,下面這篇文章主要給大家介紹了關(guān)于Vue組件封裝之input輸入框的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • vue路由傳參方式的方式總結(jié)及獲取參數(shù)詳解

    vue路由傳參方式的方式總結(jié)及獲取參數(shù)詳解

    vue 路由傳參的使用場景一般都是應(yīng)用在父路由跳轉(zhuǎn)到子路由時,攜帶參數(shù)跳轉(zhuǎn),下面這篇文章主要給大家介紹了關(guān)于vue路由傳參方式的方式總結(jié)及獲取參數(shù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • uni-app中app和webview的h5通信簡單步驟

    uni-app中app和webview的h5通信簡單步驟

    這篇文章主要介紹了如何在nvue頁面中使用webview組件,并詳細(xì)介紹了如何在h5項(xiàng)目中安裝和配置npmiy_uniwebview插件,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-02-02

最新評論