Untitled

 avatar
unknown
plain_text
6 months ago
631 B
1
Indexable
function checkIfNextDay(startTime, endTime) {
  // Convert to UTC Date objects for comparison
  let startDate = new Date(`1970-01-01T${startTime}Z`);
  let endDate = new Date(`1970-01-01T${endTime}Z`);

  // If the end time is less than the start time, it's the next day
  if (endDate < startDate) {
    // This means the end time is after midnight, on the next day.
    return "End time is on the next day.";
  } else {
    // Same day
    return "End time is on the current day.";
  }
}

// Example usage
let startTime = "23:30";  // 11:30 PM
let endTime = "01:30";    // 1:30 AM
console.log(checkIfNextDay(startTime, endTime));
Editor is loading...
Leave a Comment