Angular 5 ng-pick-datetime日期格式

Aru*_*n A 6 datetime angular5

我在@NgModule中提到的ng-pick-datetime(5.1.5)提供:OWL_DATE_TIME_LOCALE,useValue:'en-SG'用于日期格式.当我们直接从触发器打开日历时它很好.但如果直接与输入框进行交互,然后打开日历,它将变为默认格式.

import {OWL_DATE_TIME_LOCALE , OwlDateTimeModule, OwlNativeDateTimeModule} from 'ng-pick-datetime';

@NgModule({
declarations: [ParcelCreateComponent],
imports: [      
    OwlDateTimeModule,OwlNativeDateTimeModule
],
providers: [{provide: OWL_DATE_TIME_LOCALE, useValue: 'en-SG'}] 
})
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Buz*_*zzo 1

  1. 确保安装了ng-pick-datetime-moment
  2. 然后添加: import { OwlMomentDateTimeModule } from 'ng-pick-datetime-moment';
  3. 从下面修改自定义格式

    import { NgModule } from '@angular/core'; import { OwlDateTimeModule, OWL_DATE_TIME_FORMATS} from 'ng-pick-datetime'; import { OwlMomentDateTimeModule } from 'ng-pick-datetime-moment'; // See the Moment.js docs for the meaning of these formats: // https://momentjs.com/docs/#/displaying/format/ export const MY_MOMENT_FORMATS = { parseInput: 'l LT', fullPickerInput: 'l LT', datePickerInput: 'l', timePickerInput: 'LT', monthYearLabel: 'MMM YYYY', dateA11yLabel: 'LL', monthYearA11yLabel: 'MMMM YYYY', }; @NgModule({ imports: [OwlDateTimeModule, OwlMomentDateTimeModule], providers: [ {provide: OWL_DATE_TIME_FORMATS, useValue: MY_MOMENT_FORMATS}, ], }) export class AppExampleModule { }