Created
November 26, 2023 09:42
-
-
Save sefgit/c3b8be05b058500d37f7e6e07a859752 to your computer and use it in GitHub Desktop.
javascript localtime to UTC
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
let wib_time = "Nov 25, 2023, 01:05:02 GMT+7"; | |
let now = new Date(2023, 11, 25, 1, 5, 2); // localtime | |
let date_options = {timeZone:"Asia/Jakarta", hour12: false, dateStyle:"medium", timeStyle:"long"}; | |
let wib_time = now.toLocaleString("en-US", date_options); // convert to UTC string | |
let wib_date = new Date(wib_time); // convert to UTC | |
const event = new Date(wib_time); | |
console.log(event.toUTCString()); | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment