Posted at

Angular5でDatePipeを使う。LOCALEセットしてね。

More than 1 year has passed since last update.


バージョン


  • ionic 4.1.1

  • Angular 5.2.11


LOCALE設定

Angular 5 Breaking change - manually import locale - Stack Overflow


  • app.module.ts

providerにセットして、かつ、registerLocaleDataをしてやる必要がある


import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import localeJa from '@angular/common/locales/ja';
import { registerLocaleData } from '@angular/common';

registerLocaleData(localeJa);

@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
{ provide: LOCALE_ID, useValue: 'ja-JP' },
StatusBar,
SplashScreen,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule { }


DatePipe

Angular - DatePipe


  • html

<span class="msg-date">{{chat.send_at | date:'yyyy/MM/dd HH:mm'}}</span>


  • 表示

2018/09/03 09:20