网站管理后台源码聊城制作网站
有一个签到功能需要用户登录时间超过两个小时才可以签到
1. 存储登录时间戳
 login() {  // 假设这是登录后的操作  const currentTime = new Date().getTime(); // 获取当前时间戳  localStorage.setItem('loginTimestamp', currentTime.toString()); // 存储登录时间戳  // 其他登录后的操作...  
} 
2. 检查登录时间是否超过两个小时
封装一个函数
 isLoggedInMoreThanTwoHours() {  const loginTimestamp = parseInt(localStorage.getItem('loginTimestamp')) || 0; // 获取登录时间戳  const currentTimestamp = new Date().getTime(); // 获取当前时间戳  const twoHoursInMilliseconds = 2 * 60 * 60 * 1000; // 两个小时的毫秒数  // 如果登录时间戳存在且当前时间与登录时间之差大于两个小时  if (loginTimestamp && (currentTimestamp - loginTimestamp > twoHoursInMilliseconds)) {  return true; // 超过两个小时  }  return false; // 未超过两个小时  
} 
3. 使用这个函数
   checkLoginTime() {  if (this.isLoggedInMoreThanTwoHours()) {  alert('您的登录时间已超过两个小时,请重新登录!');  // 执行重新登录或其他操作  } else {  console.log('您的登录时间未超过两个小时。');  }  }, 
