本文介绍了Angular 5 ng-pick-datetime 日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 确保安装 ng-pick-datetime-moment
  2. 然后添加: import { OwlMomentDateTimeModule } from 'ng-pick-datetime-moment';
  3. 从下方修改自定义格式

  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';从 'ng-pick-datetime' 导入 { OwlDateTimeModule, OWL_DATE_TIME_FORMATS};从 'ng-pick-datetime-moment' 导入 { OwlMomentDateTimeModule };//请参阅 Moment.js 文档以了解这些格式的含义://https://momentjs.com/docs/#/displaying/format/导出常量 MY_MOMENT_FORMATS = {解析输入:'l LT',fullPickerInput: 'l LT',datePickerInput: 'l',时间选择器输入:'LT',monthYearLabel: 'MMM YYYY',dateA11yLabel: 'LL',monthYearA11yLabel: 'MMMM YYYY',};@NgModule({进口:[OwlDateTimeModule,OwlMomentDateTimeModule],供应商: [{提供:OWL_DATE_TIME_FORMATS,使用价值:MY_MOMENT_FORMATS},],})导出类 AppExampleModule {}

这篇关于Angular 5 ng-pick-datetime 日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:22