Created
March 1, 2022 12:39
-
-
Save tobiasroeder/f4ac8786674cf551466a3f67b39a9c10 to your computer and use it in GitHub Desktop.
Simple and reliable way to get date from tomorrow in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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