js 時間格式轉換


js時間格式轉換

格式化時間轉成時間戳

//格式化轉時間戳(單位秒)
                function strtotime(strtime) {
                    strtime = strtime.substring(0, 19);
                    strtime = strtime.replace(/-/g, '/');
                    strtime = new Date(strtime).getTime() / 1000;
                    return strtime;
                }

時間戳轉格式化時間

        //時間戳(單位秒)轉格式化
                function getMyDate(str) {
                    str = str * 1000;
                    var oDate = new Date(str),
                        oYear = oDate.getFullYear(),
                        oMonth = oDate.getMonth() + 1,
                        oDay = oDate.getDate(),
                        oHour = oDate.getHours(),
                        oMin = oDate.getMinutes(),
                        oSen = oDate.getSeconds(),
                        oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + ' ' + getzf(oHour) + ':' +
                        getzf(oMin) + ':00'; //最后拼接時間
                    return oTime;
                };

 


免責聲明!

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



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