Angular 5 ng-pick-datetime日期格式

时间:2018-02-09 09:18:10

标签: 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'}] 
})

enter image description here

1 个答案:

答案 0 :(得分:1)

  1. 确保您安装 ng-pick-datetime-moment
  2. 然后添加:从'ng-pick-datetime-moment'导入{OwlMomentDateTimeModule};
  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 { }