0

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

Shubham Ghormade
  • 215
  • 4
  • 16

2 Answers2

2

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);
Graham
  • 7,431
  • 18
  • 59
  • 84
sonu singhal
  • 211
  • 1
  • 6
0

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"
*/
Anandhan Suruli
  • 365
  • 3
  • 13
  • The result of [*toUTCString*](http://ecma-international.org/ecma-262/8.0/#sec-date.prototype.toutcstring) is implementation dependent and may or may not be in the OP's required format (most likely not). – RobG Feb 05 '18 at 05:00