Created
April 18, 2020 02:30
-
-
Save ChronSyn/91b7e47f745149cbe6f2002956255f49 to your computer and use it in GitHub Desktop.
Allows you to take a time from an existing Date object (or date-format string) and set todays' Date object to that time
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
const adaptTimeForToday = (time: Date | string): Date => { | |
const existingFormattedDate: Date = new Date(time); | |
const [hours, minutes, seconds]: number[] = existingFormattedDate.toLocaleTimeString().split(":").map((segment) => Number(segment)); | |
const output: Date = new Date(); | |
output.setHours(hours); | |
output.setMinutes(minutes); | |
output.setSeconds(seconds); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment