Skip to content

Instantly share code, notes, and snippets.

@mark05e
Created January 12, 2022 21:42
Show Gist options
  • Save mark05e/e620784e23c9ea9beeb610623a83046b to your computer and use it in GitHub Desktop.
Save mark05e/e620784e23c9ea9beeb610623a83046b to your computer and use it in GitHub Desktop.
Convert a UTC datetime to browser local datetime.
var utcDatetime = "01/12/2022 07:57 PM"
var options = {day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute:'2-digit' };
var myDateTime = new Date(utcDatetime + ' UTC').toLocaleString("en-US",options)
// myDateTime : 01/12/22, 02:57 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment