Reputation: 5135
I have an API which gives me the following info
Backend API:
/api/time
{
"timeZoneOffset": -18000000, (milli sec)
"serverTimeUTC": 1485332569157,
"serverTime": "Wed Jan 25 03:22:49 EST 2017",
"timeZone": "Eastern Standard Time"
}
I have another API through which I get time from reports
API: /reports/
{
"reportTime": "01/24/2017 12:06 AM"
}
How can I display the reportTime in local system time? (browser time?)
I've tried:
browserTime = moment(reportTime).utcOffset(moment().utcOffset()).format('MM/DD/YYYY h:mm A');
(I'm currently in PST so offset is -480)
I'm not able to get this working. Please help.
Upvotes: 1
Views: 428
Reputation: 2330
You can convert reportTime
to local time by doing:
var localTime = moment.utc(reportTime).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');
More convinient way use http://momentjs.com/timezone/. It enables conversion from EST to PST
Upvotes: 1