Skip to content

Instantly share code, notes, and snippets.

@jdgo-mars
Last active December 10, 2020 11:49
Show Gist options
  • Save jdgo-mars/2a2515034b29545abba769561eef9e11 to your computer and use it in GitHub Desktop.
Save jdgo-mars/2a2515034b29545abba769561eef9e11 to your computer and use it in GitHub Desktop.
const weekday = {
0: "Sunday",
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
}
function getToday() {
const today = new Date();
const todayString = `It's ${weekday[today.getDay()]}! It's ${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}`;
$('#currentTimeParagraph').text(todayString);
}
function daysLeft() {
const today = new Date();
const urlParams = new URLSearchParams(window.location.search);
const targetYear = urlParams.get('targetYear') | today.getFullYear();
const christmas = new Date();
christmas.setDate(24);
christmas.setMonth(11);
const diff = christmas.getTime() - today.getTime();
const yearDiff = targetYear - today.getFullYear()
$('#christmasTime').text(`Days until Christmas: ${diff / (1000 * 60 * 60 * 24) + (365 * yearDiff)} days`);
}
$(document).ready(() => {
daysLeft();
getToday();
setInterval(getToday, 1000);
});
// run `npx http-server` on your project folder
// open `localhost:8080` on browser
// try using a targetYear
// using url `localhost:8080?targetYear=2021`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment