Created
February 25, 2022 10:38
-
-
Save SebastianUdden/e3e63c720e51d85327e8d5971e7c30e5 to your computer and use it in GitHub Desktop.
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
| const getLeadingZero = number => (number < 10 ? `0${number}` : number) | |
| export const formatDate = dateString => { | |
| const dateTime = new Date(dateString) | |
| const year = dateTime.getFullYear() | |
| const month = getLeadingZero(dateTime.getMonth() + 1) | |
| const day = getLeadingZero(dateTime.getDate()) | |
| const hours = getLeadingZero(dateTime.getHours()) | |
| const minutes = getLeadingZero(dateTime.getMinutes()) | |
| return { date: `${year}-${month}-${day}`, time: `${hours}:${minutes}` } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment