uni-app位置相关笔记/获取到当天零点和12点的时间戳

function getDayTimestamps(offset) {
  const currentDate = new Date();
  
  const targetDate = new Date(currentDate);
  targetDate.setDate(currentDate.getDate() - offset);
  
  targetDate.setHours(0, 0, 0, 0);
  const startTime = targetDate.getTime();

  targetDate.setHours(23, 59, 59, 999);
  const endTime = targetDate.getTime();
  
  return {
    startTime,
    endTime
  };
}

const yesterday = getDayTimestamps(1);
const twoDaysAgo = getDayTimestamps(2);

console.log("昨天开始时间戳:", yesterday.startTime);
console.log("昨天结束时间戳:", yesterday.endTime);
console.log("前两天开始时间戳:", twoDaysAgo.startTime);
console.log("前两天结束时间戳:", twoDaysAgo.endTime);

猜你喜欢

转载自blog.csdn.net/m0_73358221/article/details/131768428