0

I am getting a date from backend in this form '2020-10-13T12:37:12.636230Z' I need to change it into dd.mm.yyyy only form. So how to parse a data coming from backend to a dd.mm.yyyy. Thank you.

UPD: I didnt explain correctly I guess. Im getting a lot of date feom back to my front in this form 'YYYY-mm-dd T HH:mm:ss.xxZ'. So i need to convert it into DD.MM.YY HH.mm.ss

GGotchaA
  • 165
  • 1
  • 1
  • 10
  • 1
    Does this answer your question? [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – anttud Oct 19 '20 at 06:25
  • You mean, you want to *format* a date to a specific format. – Panagiotis Kanavos Oct 19 '20 at 06:31
  • yep, I didnt explain correctly I guess. Im getting a lot of date feom back to my front in this form 'YYYY-mm-dd T HH:mm:ss.xxZ'. So i need to convert it into DD.MM.YY HH.mm.ss – GGotchaA Oct 19 '20 at 06:51
  • JavaScript's `Date` object can parse the ISO8601 format directly. You can format a Date using any of the `to...String()` methods, although they don't allow you to specify any format. JavaScript is rather limited when it comes to dates. If `toLocaleDateString()` doesn't produce what you want you may have to use a separate library like date-fns – Panagiotis Kanavos Oct 19 '20 at 07:16

2 Answers2

2

You can try Date#toLocaleDateString()

const source = '2020-10-13T12:37:12.636230Z';
const date = new Date(source).toLocaleDateString('de-DE');

console.log(date);
Hao Wu
  • 17,573
  • 6
  • 28
  • 60
0

You can achive this using this method

const formateDate = (inputVal) => {
        inputVal = new Date(inputVal);
        let dd = inputVal.getDate(), 
        mm = inputVal.getMonth() + 1,
        yyyy = inputVal.getFullYear();

        if (dd < 10) { 
            dd = '0' + dd; 
        } 
        if (mm < 10) { 
            mm = '0' + mm; 
        }

        return dd + '.' + mm + '.' + yyyy;
}


formateDate('2020-10-13T12:37:12.636230Z');