[英]Page last modified using Javascript with 12 hour clock showing am or pm
I'm trying to create a script in Javascript that shows when a page was last modified, which returns the date, time, in am or pm format, of modification. 我正在尝试使用Javascript创建一个脚本,该脚本显示页面的上一次修改时间,该页面以am或pm格式返回修改的日期,时间。
Clearly I am doing something wrong. 显然我做错了。 I can't get the script to run, and it will be in my function AmPm. 我无法运行该脚本,它将在我的函数AmPm中。 Can someone please help? 有人可以帮忙吗?
// 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.