Created
February 11, 2019 11:53
-
-
Save sergiks/2da3e3b93ff98e3b05d0b80fa6198cf3 to your computer and use it in GitHub Desktop.
JS function to get nearest end of week date time as a YYY/MM/DD HH:ii:ss string
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
/** | |
* returns date-time of the nearest week end | |
* as a string "YYYY/MM/DD HH:ii:ss" | |
*/ | |
function getEndOfWeek() { | |
const D = new Date(); | |
D.setDate(D.getDate() - D.getDay() + (D.getDay() ? 7 : 0)); | |
D.setHours(23, 59 - D.getTimezoneOffset(), 59, 0); | |
return D.toISOString().slice(0, 19).replace('T', ' ').replace(/-/g,'/'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment