Date format - ionic 4

I was trying to format my date which shows as

Sat Oct 26 2019 16:33:36 GMT+0530 (India Standard Time)

but i wanted to show this as 26/10/2019.

finally found a solution and I’m posting this for everyone who is looking for a solution.

let birthdate = new Date(this.dob).toLocaleDateString('en-GB')

toLocaleDateString(‘en-GB’) method will save your day!

If you want to show month before date as the format mm/dd/yyyy
eg: 10/26/2019




Another option would be to use date-fns and just say:

format(new Date(this.dob), "dd/MM/yyyy")

This will give you more fine-grained control over what to do with leading zeroes, in addition to being more clear to readers.

1 Like