亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    vuejs怎么把時(shí)間戳變成日期

    vuejs把時(shí)間戳變成日期的方法:1、創(chuàng)建date.js文件并保存到公共js文件夾中;2、在需要格式化時(shí)間戳的組件里使用“formatDate(date, 'yyyy-MM-dd hh:mm');”方法進(jìn)行轉(zhuǎn)換即可。

    vuejs怎么把時(shí)間戳變成日期

    本文操作環(huán)境:Windows7系統(tǒng)、vue2.9.6版,DELL G3電腦。

    vuejs怎么把時(shí)間戳變成日期?

    vue.js將時(shí)間戳轉(zhuǎn)化為日期格式:

    <!– value 格式為13位unix時(shí)間戳 –>

    <!– 10位unix時(shí)間戳可通過(guò)value*1000轉(zhuǎn)換為13位格式 –>

    export function formatDate (date, fmt) {     if (/(y+)/.test(fmt)) {         fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));     }     let o = {         'M+': date.getMonth() + 1,         'd+': date.getDate(),         'h+': date.getHours(),         'm+': date.getMinutes(),         's+': date.getSeconds()     };     for (let k in o) {         if (new RegExp(`(${k})`).test(fmt)) {             let str = o[k] + '';             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));         }     }     return fmt; }; function padLeftZero (str) {     return ('00' + str).substr(str.length); };

    把上面代碼保存為date.js放到你的公共js文件夾中。

    在你的需要格式化時(shí)間戳的組件里像下面這樣使用:

    <template>     <!-- 過(guò)濾器  time 可以使后臺(tái)得到的數(shù)據(jù),循環(huán)出來(lái)的也行 -->     <div>{{time | formatDate}}</div>     <!-- 輸出結(jié)果 -->     <!-- <div>2016-07-23 21:52</div> --> </template> <script> import {formatDate} from './common/date.js'; export default {     filters: {         formatDate(time) {             var date = new Date(time);             return formatDate(date, 'yyyy-MM-dd hh:mm');         }     } } </script>

    這樣就好了

    推薦:《最新的5個(gè)vue.js視頻教程精選》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)