JS 日期與時間戮相互轉(zhuǎn)化的簡單實例

字號:


    下面小編就為大家?guī)硪黄狫S 日期與時間戮相互轉(zhuǎn)化的簡單實例。小編覺得挺不錯的, 現(xiàn)在就分享給大家,也給大家做個參考。
    1、日期格式轉(zhuǎn)時間戮 
    function getTimestamp(time) 
     {
       return Date.parse(new Date(time));
     }
    2、時間戮轉(zhuǎn)日期格式 
    function transformPHPTime(time) 
    {
     var date = new Date(time * 1000);
        Y = date.getFullYear() + '-';
     M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
     D = date.getDate() + ' ';
     h = date.getHours() + ':';
     m = date.getMinutes() + ':';
     s = date.getSeconds();
     return Y+M+D+h+m+s;
    }
    以上就是小編為大家?guī)淼腏S 日期與時間戮相互轉(zhuǎn)化的簡單實例全部內(nèi)容了