简体   繁体   English

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

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

相关问题 12 小时 Javascript 时钟显示 24 时间,错误的 AM/PM - 12 hour Javascript Clock Showing 24 time, Wrong AM/PM 如果用户的机器使用 12 小时制(上午/下午)或 24 小时制(军用时间),则使用 javascript 检测 - Detect with javascript if user's machine is using 12 hour clock (am/pm) or 24 clock (military time) 将 24 小时制转换为 12 小时制并跟踪 AM/PM - Converting a 24 hour clock to a 12 hour clock and keeping track of AM/PM 使用 Javascript 将 24 小时制转换为 12 小时制 - Converting 24 hour time to 12 hour time w/ AM & PM using Javascript 需要12小时格式而不显示AM / PM Timepicker - Need 12 hour format without showing AM/PM Timepicker 每当时钟在12 AM或12 PM时刷新网页的程序 - A program to refresh web page whenever clock ticks 12 AM or 12 PM Javascript:将 24 小时时间字符串转换为带有 AM/PM 且无时区的 12 小时时间 - Javascript: convert 24-hour time-of-day string to 12-hour time with AM/PM and no timezone 如何以 12 小时 AM/PM 格式显示 JavaScript 日期时间? - How do you display JavaScript datetime in 12 hour AM/PM format? 如何在JavaScript时钟中设置上午pm - How to set am pm in javascript clock 使用时刻 js 将 12 小时 (AM/PM) 字符串转换为 24 日期对象 - Convert 12 hour (AM/PM) string to 24 Date object using moment js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM