Last active
February 11, 2019 06:14
-
-
Save HerbertLim/a28c490025a45e476862ef6a49f49331 to your computer and use it in GitHub Desktop.
Get UTC hours and minutes from local time format, "08:15"
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
// parameter hmTime is a string containing 5 characters, | |
// first two is hours, last to is minutes, which are divied with ':', | |
// e.g., "08:15", "17:43" | |
const _ = require('lodash'); | |
function localHhMmToUtc(hmTime) { | |
const splitted = _.split(hmTime, ':') | |
const localHours = splitted[0]; | |
const localMinutes = splitted[1]; | |
const date = new Date() | |
const now = new Date(date.getFullYear(), date.getMonth(), date.getDate(), localHours, localMinutes) // UTC | |
const utcHours = now.getUTCHours() | |
const utcMinutes = now.getUTCMinutes() | |
return {utcHours, utcMinutes} // returns an object containing UTC hours and minutes, respectively. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment