vue實例獲取當前系統時間


vue實例獲取當前系統時間

效果圖:

 代碼:

<template>
    <div class="home1-3-1 clearfix">
        <span>{{ nowDate }}</span>
        <p> <em>{{ nowYear }}.{{ nowMouth }}</em> <i>{{ nowWeek }}</i> </p>
    </div>
</template>  
<script>
export default {
    data () {
        return {
            nowYear: '',
            nowMouth: '',
            nowDate: '',
            nowWeek: ''
        }
    },
    mouted(){
        this.getdate()
   },
    methods:{
        getdate() {
        const year = new Date().getFullYear()
        const mounth = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1)
        const date = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
        const week = new Date().getDay()
        if (week === 1) {
          this.nowWeek = '星期一'
        } else if (week === 2) {
          this.nowWeek = '星期二'
        } else if (week === 3) {
          this.nowWeek = '星期三'
        } else if (week === 4) {
          this.nowWeek = '星期四'
        } else if (week === 5) {
          this.nowWeek = '星期五'
        } else if (week === 6) {
          this.nowWeek = '星期六'
        } else if (week === 27) {
          this.nowWeek = '星期日'
        }
        this.nowYear = year
        this.nowMouth = mounth
        this.nowDate = date
      }
    }
}
</script>   

 

css樣式我沒有寫,需要時分秒再通過其對應方法獲取即可,年月日也可以進行拼接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM