Created
March 9, 2025 22:04
-
-
Save pinalbhatt/03ca98f08f9e193aeebe2293657f2ed0 to your computer and use it in GitHub Desktop.
js-since
This file contains hidden or 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
function getPastRoundedHours() { | |
const formattedDate = (date) => { | |
const year = date.getFullYear(); | |
const month = String(date.getMonth() + 1).padStart(2, '0'); | |
const day = String(date.getDate()).padStart(2, '0'); | |
const hours = String(date.getHours()).padStart(2, '0'); | |
return `${year}-${month}-${day} ${hours}:00:00`; | |
} | |
const now = new Date(); | |
now.setMinutes(0, 0, 0); | |
const previousHour1 = new Date(now); | |
const previousHour2 = (new Date(previousHour1)); | |
previousHour2.setHours(previousHour2.getHours() - 1); | |
return `SINCE ${formattedDate(previousHour2)} UNTIL ${formattedDate(previousHour1)}`; | |
} | |
console.log( getPastRoundedHours()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment