0

I am trying to format my DateTime string I retrieve from an API from YYYY-MM-DDTHH:MM: SS +08:00 to DD-MM-YY HH: MM

retrieveApiData(res) {
    this.time = this.time.items[0].timestamp;
    console.log(this.time);
    document.getElementById("time").textContent = "Time Taken: " + this.time;
}

My console log result: 2020-06-17T11:20:00+08:00

John
  • 1
  • 4
    Does this answer your question? [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – jpthesolver2 Jun 17 '20 at 03:49
  • 1
    Take a look to this answer https://stackoverflow.com/a/13219636/615274 – Mario Jun 17 '20 at 03:50

1 Answers1

0

You can Try this way

var date = new Date(this.time);
console.log(date.toLocaleString('en-GB', { timeZone: 'UTC' }));

var date = new Date();
console.log(date.toLocaleString('en-GB', { timeZone: 'UTC' }).replace(/\//g,'-'));
Narendra Chouhan
  • 2,140
  • 1
  • 9
  • 17