1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Global date format config

Discussão em 'Angular' iniciado por Varun Sukheja, Julho 2, 2025.

  1. I am using Angular8 and want to format date and time but I have to use date pipe with same format pattern again and again as shown below

    <p>{{ myDate | date: 'dd MMM yyyy, h:mm a' }}</p>
    <p>{{ myOtherDate date: 'dd MMM yyyy, h:mm a' }}</p>
    <p>{{ otherVar }}</p>
    <p>{{ myOtherOtherDate date: 'dd MMM yyyy, h:mm a' }}</p>


    and same format date: 'dd MMM yyyy, h:mm a' is to be used in each and every component of my project.

    Is there a way where I can provide a global config in the providers of my App Module, something like this

    @NgModule({
    providers: [
    {provide: LOCAL_PIPE_DATE_PATTERN, useValue: 'ddMMyy'},
    ],
    })
    export class AppModule {}


    and just use the date pipe as

    <p>{{ myDate | date }}</p>
    <p>{{ myOtherDate | date }}</p>
    <p>{{ otherVar }}</p>
    <p>{{ myOtherOtherDate | date:'MMyyDD' }}</p> (If format changed)

    Continue reading...

Compartilhe esta Página