0

I have a string:

var utc_datetime = "02/09/2018 1:27 a.m."

I need it to show up in the user's local time. The format will always be the same, and it will always be queried in UTC timezone.

How can I accomplish this? I tried moment, and moment-timezone, but no luck so far.

Durga
  • 15,263
  • 2
  • 28
  • 52
Scott Stoltzman
  • 363
  • 1
  • 15

1 Answers1

1

Remove the dots and capitalize the AM or PM: Append 'UTC' to the string then convert it to a date

var utc_datetime = "02/09/2018 1:27 a.m."
var new_datestring = utc_datetime.replace(/\./g,'').toUpperCase() + ' UTC';
var date = new Date(new_datestring);
var local_datetime = date.toString();
console.log(local_datetime)
Durga
  • 15,263
  • 2
  • 28
  • 52
Sunny
  • 96
  • 4