Angular 5 ng-pick-datetime date format

五迷三道 提交于 2021-01-27 05:05:26

问题


I have mentioned for ng-pick-datetime(5.1.5) in @NgModule provide: OWL_DATE_TIME_LOCALE, useValue: 'en-SG' for date format. Its fine when we open the calendar directly from trigger. But if directly interacted with input box and then opened the calendar it will get change into default format.

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


回答1:


  1. Make sure you install ng-pick-datetime-moment
  2. Then add: import { OwlMomentDateTimeModule } from 'ng-pick-datetime-moment';
  3. Modify custom formats from below

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



来源:https://stackoverflow.com/questions/48702408/angular-5-ng-pick-datetime-date-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!