Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created March 1, 2022 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/f4ac8786674cf551466a3f67b39a9c10 to your computer and use it in GitHub Desktop.
Save tobiasroeder/f4ac8786674cf551466a3f67b39a9c10 to your computer and use it in GitHub Desktop.
Simple and reliable way to get date from tomorrow in JavaScript.
// main idea from https://www.youtube.com/watch?v=PNjNFatebgY&lc=UgzPj8mKHXk4akXfLcR4AaABAg
function getTomorrow( date = Date.now() ) {
let today = new Date(date);
let tomorrow = today.setDate(today.getDate() + 1);
return tomorrow;
}
function formatDate( date ) {
return new Date(date).toLocaleString();
}
console.log(formatDate(getTomorrow()));
console.log(formatDate(getTomorrow('2022-12-31 00:00:00')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment