vue 타임 스탬프를 날짜로 바꾸는 방식

5851 단어
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);
};


           js , vue        ,     ,    
 
  
 
  

<span style="line-height:1.5 !important;">
import {formatDate} </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">from</span> <span style="color:rgb(128,0,0);line-height:1.5 !important;">'</span><span style="color:rgb(128,0,0);line-height:1.5 !important;">./common/date.js</span><span style="color:rgb(128,0,0);line-height:1.5 !important;">'</span><span style="line-height:1.5 !important;">;
export </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">default</span><span style="line-height:1.5 !important;"> {
    filters: {
        formatDate(time) {
            </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">var</span> date = <span style="color:rgb(0,0,255);line-height:1.5 !important;">new</span><span style="line-height:1.5 !important;"> Date(time);
            </span><span style="color:rgb(0,0,255);line-height:1.5 !important;">return</span> formatDate(date, 'yyyy-MM-<span style="line-height:1.5 !important;">dd hh:mm');
        }
    }
}
</span>
 
  
 
  
         

좋은 웹페이지 즐겨찾기