Angular10 getLocaleDateFormat() Function
In this article, we are going to see what is getLocaleDateFormat in Angular 10 and how to use it.
The getLocaleDateFormat is used to get the localized date-value formating for the given locale. Syntax: NgModule: Module used by getLocaleDateFormat is: Approach: Parameters: Return value: Example 1: Output: Example 2: Output: Reference: https://angular.io/api/common/getLocaleDateFormatgetLocaleDateFormat(locale: string, width: FormatWidth): string
import { LOCALE_ID, NgModule } from '@angular/core';app.module.ts
import { LOCALE_ID, NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module';import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AppRoutingModule ], providers: [ { provide: LOCALE_ID, useValue: 'en-GB' }, ], bootstrap: [AppComponent]})export class AppModule { }app.component.ts
import {FormStyle, getLocaleDateFormat, TranslationWidth, FormatWidth} from '@angular/common'; import {Component, Inject,OnInit, LOCALE_ID } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html'})export class AppComponent { for = getLocaleDateFormat(this.locale, FormatWidth.Short); constructor( @Inject(LOCALE_ID) public locale: string,){} }app.component.html
<h1> GeeksforGeeks</h1><p>Date format is: {{for}}</p>app.module.ts
import { LOCALE_ID, NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module';import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AppRoutingModule ], providers: [ { provide: LOCALE_ID, useValue: 'en-GB' }, ], bootstrap: [AppComponent]})export class AppModule { }app.component.ts
import {FormStyle, getLocaleDateFormat, TranslationWidth, FormatWidth} from '@angular/common'; import {Component, Inject, LOCALE_ID } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html'})export class AppComponent { for = getLocaleDateFormat(this.locale, FormatWidth.Long); constructor( @Inject(LOCALE_ID) public locale: string,){} }app.component.html
<h1> GeeksforGeeks</h1><p>Date format is: {{for}}</p>


