Just wanted a code how a UTC time converted to browser local time and vice versa dynamically without using moment.js needed only pure angular
Tried with Using AngularJS date filter with UTC date but i want dynamic conversion
Just wanted a code how a UTC time converted to browser local time and vice versa dynamically without using moment.js needed only pure angular
Tried with Using AngularJS date filter with UTC date but i want dynamic conversion
Add UTC
at the end of the DateTime string before converting it to a date
example:
var date = new Date('2/16/2017 10:51:23 PM UTC');
console.debug(date.toLocaleTimeString()) // "5:51:23 PM"
Here is how you can change the date to local and UTC.
var d = new Date();
document.getElementById("date").innerHTML = d;
document.getElementById("local").innerHTML = d.toLocaleTimeString();
document.getElementById("utc").innerHTML = d.toUTCString();
document.getElementById("fromutc").innerHTML = Date(d.toUTCString());
Date => <span id="date"></span><br>
Local => <span id="local"></span><br>
UTC => <span id="utc"></span><br>
FromUTC => <span id="fromutc"></span><br>
Also find here the reference of all the dateTime functions available in javascript