[英]Page last modified using Javascript with 12 hour clock showing am or pm
我正在嘗試使用Javascript創建一個腳本,該腳本顯示頁面的上一次修改時間,該頁面以am或pm格式返回修改的日期,時間。
顯然我做錯了。 我無法運行該腳本,它將在我的函數AmPm中。 有人可以幫忙嗎?
// Javascript code for page modification // Shows the date, time, am or pm, of modification. // This section sets the date of modification function lastModified() { var modiDate = new Date(document.lastModified); var showAs = modiDate.getDate() + "." + (modiDate.getMonth() + 1) + "." + modiDate.getFullYear(); return showAs } // This section sets the time of modification function GetTime() { var modiDate = new Date(); var Seconds if (modiDate.getSeconds() < 10) { Seconds = "0" + modiDate.getSeconds(); } else { Seconds = modiDate.getSeconds(); } // This section writes the above in the document var modiDate = new Date(); var CurTime = modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds return CurTime } // This section decides if its am or pm function AmPm() { var hours = new Date().getHours(); var hours = (hours + 24 - 2) % 24; var mid = 'AM'; if (hours == 0) { // At 00 hours (midnight) we need to display 12 am hours = 12; } else if (hours > 12) // At 12pm (Midday) we need to display 12 pm { hours = hours % 12; mid = 'PM'; } } var mid = //This is where I am stuck!! return AmPm document.write("This webpage was last edited on: "); document.write(lastModified() + " at " + GetTime() + AmPm()); document.write(""); document.write(" NZ Daylight Savings Time."); document.write("");
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.