時間戳轉換爲"yyyy-MM-dd hh:mm:ss"格式(24小時)

//時間戳格式化
                                        value="/Date(1451466990767)/";
				        Otime = value.replace("/Date(", "").replace(")/", "").substr(0, 10);
                        //此時Otime=「1451466990」
				        function formatDate(now) {
				            var year = now.getFullYear();
				            var month = now.getMonth() + 1;
				            if (month < 9) {
				                month = "0" + month;
				            }
				            var date = now.getDate();
				            if (date < 9) {
				                date = "0" + date;
				            }
				            var hour = now.getHours();
				            if (hour < 9) {
				                hour = "0" + hour;
				            }
				            var minute = now.getMinutes();
				            if (minute < 9) {
				                minute = "0" + minute;
				            }
				            var second = now.getSeconds();
				            if (second < 9) {
				                second = "0" + second;
				            }
				            return year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
				        }
				        var d = new Date(parseInt(Otime) * 1000);
				        alert(formatDate(d));
                                        //彈出結果爲2015-12-30 17:16:30
相關文章
相關標籤/搜索