Skip to content

Instantly share code, notes, and snippets.

@hallojoe
Last active January 20, 2021 11:14
Show Gist options
  • Save hallojoe/a00b40af4980231533e6446d3f96ac30 to your computer and use it in GitHub Desktop.
Save hallojoe/a00b40af4980231533e6446d3f96ac30 to your computer and use it in GitHub Desktop.
Inherit time from source date time
function inheritTimeFrom(source, target) {
var sourceDateTime = new Date(source)
var targetDateTime = new Date(target)
targetDateTime.setHours(sourceDateTime.getHours())
targetDateTime.setMinutes(sourceDateTime.getMinutes())
targetDateTime.setSeconds(sourceDateTime.getSeconds())
targetDateTime.setSeconds(sourceDateTime.getMilliseconds())
return targetDateTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment