Skip to content
Related Articles

Related Articles

Angular10 getLocaleDayPeriods() Function

Improve Article
Save Article
  • Last Updated : 04 Aug, 2021
Improve Article
Save Article

In this article, we are going to see what is getLocaleDayPeriods in Angular 10 and how to use it.

The getLocaleDayPeriods used to get the day period strings for the given locale.


getLocaleDayPeriods(locale: string, 
                    formStyle: FormStyle, 
                    width: TranslationWidth)

NgModule: Module used by getLocaleDayPeriods is:

  • CommonModule


  • Create the angular app to be used
  • In app.module.ts import LOCALE_ID because we need locale to be imported for using get getLocaleDayPeriods.
import { LOCALE_ID, NgModule } from '@angular/core';
  • In app.component.ts import getLocaleDayPeriods and LOCALE_ID
  • inject LOCALE_ID as a public variable.
  • In app.component.html show the local variable using string interpolation
  • serve the angular app using ng serve to see the output.


  • locale: A string containing locale code with rules.
  • width: The character width.
  • formStyle: The form style.

Return value:

  • array: array of localized period strings.

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';
  declarations: [
  imports: [
  providers: [
      { provide: LOCALE_ID, useValue: 'en-GB' },
  bootstrap: [AppComponent]
export class AppModule { }


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


 <p>Locale Time is : {{dir}}</p>



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!