Input:- 2018-01-19T17:04:54.923Z;
Output:- 2018-01-19 17:04:54;
How can I get universal logic which will work in all browsers in JAVASCRIPT
Input:- 2018-01-19T17:04:54.923Z;
Output:- 2018-01-19 17:04:54;
How can I get universal logic which will work in all browsers in JAVASCRIPT
You can use this:
var dt = new Date('2018-01-19T17:04:54.923Z');
var formatedString = dt.getFullYear() + "-" + dt.getMonth() + 1 + "-" + dt.getDate() + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
console.log(formatedString);
In javascript you can convert UTC date to local date format using below snippets.
// Your input date
var utcDate = new Date('2018-01-19T17:04:54.923Z');
//Converted UTC to local(IST, etc.,,)
console.log(utcDate.toUTCString());
/*
Output is : "Fri, 19 Jan 2018 17:04:54 GMT"
*/