I am looking to move from momentjs to date-fns. Although I have been trying for couple of hours, I am not able to get the correct format, period, timelines, etc… I could not find date-fns official guide of much use. I will be glad if anyone can suggest a tutorial, a link, or examples on how they have used it on their specific page with HTML and TS samples.
How do you set the locale in the div? I assume you must import it in the pipe. Could you tell me how to do that?
I tried the following {{ post.posted | dateformat: ‘ddd D YYYY’, { locale: es } }} but got Object object in return.
You would need to do a couple of things: first add an options parameter to the pipe, and pass it through to format(). Then you need to change slightly the way you delineate the parameters in the template: multiple pipe parameters are separated by colons not commas.
If anyone has a minute to look at this - when I try this, I get:
Argument of type ‘string | Date’ is not assignable to parameter of type ‘number | Date’.
Type ‘string’ is not assignable to type ‘number | Date’.ts(2345)
I am pretty much a beginner at Ionic
PS - my locale is “en-NZ” so maybe that is causing the problem??
No, what’s causing the problem is that this thread is several years old, and this major version upgrade happened in the meantime. Pay special attention to the section about how strings aren’t supported in v2 any more.
Thanks, rapropos - yes, I’m using the latest - but the underlying problem is that I am just learning my way around integrating things into a model Ionic/Angular setup I have inherited. Not a problem - I fixed that issue; created more Thanks very much for the response!