-1

I have the following date and unsure how to convert it to DD/MM/YYYY HH24:MI:SS, i.e.:

"2021-04-23T05:36:59.486Z"

From what I can see, the time that was suppled was 15:36:59 which doesn't seem to match T05:36:59.486Z

tonyf
  • 34,479
  • 49
  • 157
  • 246

2 Answers2

1

The above string shows the date in ISO Format and the timezone is "+00:00". Your local timezone may be different. Refer 55246983

1upkd
  • 56
  • 5
  • It's more useful to use the question title ("*Javascript - Convert ISO8601 UTC time to client's local time*") as the link text rather than its reference number as it gives a hint as to what to expect at the other end. :-) – RobG Apr 23 '21 at 23:03
  • Thanks a lot, I'm new to the answering game here :) – 1upkd Apr 25 '21 at 04:20
0

You can use the to toLocaleString method

const 
  d = new Date().toLocaleString(),
  date = d.split(",")[0],
  time = d.split(",")[1].trim();

console.log(date);
console.log(time);
Som Shekhar Mukherjee
  • 4,701
  • 1
  • 12
  • 28
  • The output of *Date.prototype.toLocaleString* is implementation dependent and my not be the format you expect. In particular, there may not be any commas to split on. – RobG Apr 23 '21 at 23:01