Search code examples
angularwebpacklocaledate-formatting

Not able to use datepipe with locale format


I am building website using angular2 final and webpack cli. I have requirement to display date in locale nl-NL, my html code looks like:

{{eventDate | date:'d MMMM y'}}

it displays date like:

5 January 2016

It should display

5 januari 2016

any help will be much appreciated, Thanks in advance.


Solution

  • Since RC6, there is an option to set default locale. You can do it in your AppModule, first you need to import LOCALE_ID:

    import { LOCALE_ID } from '@angular/core';
    

    Then you can change its default us-US value in your module's providers, in your case nl-NL:

    @NgModule({
        imports: [...],
        declarations: [...],
        bootstrap: [...],
        providers: [
            { provide: LOCALE_ID, useValue: "nl-NL" }
        ]
    })
    

    Here's working plnkr: http://plnkr.co/edit/YRULhoEqurClE8G16TlC?p=preview