jquery 時間戳轉化為日期時間格式,年月日 時分秒


  <script type="text/javascript">        
        var strDate = '';
        $(function(){
            // 獲取時間戳  時間戳為10位需*1000,時間戳為13位的話則不用
            var nowDate = new Date().getTime(); //1564624526889
            // 調用封裝好的時間轉換方法
            timestampToTime(nowDate);
        }())
        
        function timestampToTime(timestamp) {
            var date = new Date(timestamp);
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
            var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
            var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
            var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
            
            strDate = Y+M+D+h+m+s;
            return strDate;
            
        }
        console.log(strDate) //2019-08-01 09:55:26
    </script>

  


免責聲明!

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



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