Open In App

Angular10 getLocaleFirstDayOfWeek() Function

In this article, we are going to see what is getLocaleFirstDayOfWeek in Angular 10 and how to use it. The getLocaleFirstDayOfWeek is used to get the first day of the week for the given locale.

Syntax:



getLocaleFirstDayOfWeek(locale : string): WeekDay

NgModule: Module used by FirstDayOfWeek is:

Approach: 



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

 

Parameters:

Return value:

Example 1:




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 { }




import {getLocaleFirstDayOfWeek } from '@angular/common';
  
import { Component, Inject,OnInit, LOCALE_ID } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    day = getLocaleFirstDayOfWeek(this.locale);
    dd = '';
    constructor(
        @Inject(LOCALE_ID) public locale: string,){
            if(this.day==0){
                this.dd = 'Sunday';
            }
        }
}




<h1>
  GeeksforGeeks
</h1>
  
<p>First Days of week : {{dd}}</p>

Output:

Example 2:




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 { }




import {getLocaleFirstDayOfWeek } from '@angular/common';
  
import { Component, Inject, LOCALE_ID } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    day = getLocaleFirstDayOfWeek(this.locale);
    constructor(
        @Inject(LOCALE_ID) public locale: string,){
        }
}




<h1>
  GeeksforGeeks
</h1>
  
<p>index value of first Day of week : {{day}}</p>

Output:

Reference: https://angular.io/api/common/getLocaleFirstDayOfWeek


Article Tags :