Skip to content

Instantly share code, notes, and snippets.

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 rgaz1962/bc07d6cdacb39a631240148a19761472 to your computer and use it in GitHub Desktop.
Save rgaz1962/bc07d6cdacb39a631240148a19761472 to your computer and use it in GitHub Desktop.
Friday January 14 2022 0923 AM ~ JavaScript Dates
<!-- CSS Center => cssc;01 -->
<style>
body {
width: 90%;
height: 100%;
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
<h1>JavaScript Dates</h1>
<h3>Friday January 14 2022 0924 AM</h3>
<h3>Check the Console for Results</h3>
// How to get the date, yesterday, today, tomorrow in JavaScript
const today = new Date();
const yesterday = new Date(today);
const tomorrow = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
tomorrow.setDate(tomorrow.getDate() + 1);
// You can use the DateTimeFormat object to also format it.
const config = {
year: "numeric",
month: "short",
day: "2-digit"
};
const DTF = new Intl.DateTimeFormat("default", config);
// JavaScript Console Log => cl;0
console.log(DTF.format(yesterday));
console.log(DTF.format(today));
console.log(DTF.format(tomorrow));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment