A Pen by Robert Gorman on CodePen.
Created
January 14, 2022 14:41
-
-
Save rgaz1962/bc07d6cdacb39a631240148a19761472 to your computer and use it in GitHub Desktop.
Friday January 14 2022 0923 AM ~ JavaScript Dates
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
<!-- 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> |
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
// 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