繁体   English   中英

最后使用Javascript修改的页面,其12小时制显示am或pm

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM