Skip to content

Instantly share code, notes, and snippets.

@RaphaelAudet
Last active June 26, 2023 17:08
Show Gist options
  • Save RaphaelAudet/3768b7e49a12aef5c369b77dd08c1a94 to your computer and use it in GitHub Desktop.
Save RaphaelAudet/3768b7e49a12aef5c369b77dd08c1a94 to your computer and use it in GitHub Desktop.
// Function to calculate the number of milliseconds left until 13:00 Paris time
function calculateMillisecondsLeft() {
const now = new Date();
const parisTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 0, 0); // Set the desired time (13:00)
const timeUntilParisTime = parisTime - now; // Time difference until 13:00 Paris time
const millisecondsLeft = Math.floor(timeUntilParisTime);
return millisecondsLeft;
}
// Function to wait for the specified duration in milliseconds and then navigate
function waitForDurationAndNavigate(durationInMilliseconds) {
setTimeout(function() {
const desiredUrl = "https://example.com";
window.location.href = desiredUrl;
}, durationInMilliseconds);
}
// Calculate the number of milliseconds left until 13:00 Paris time
const millisecondsLeft = calculateMillisecondsLeft();
// Wait for the calculated duration and then navigate to example.com
waitForDurationAndNavigate(millisecondsLeft);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment