angular 6 owldatetime输入格式,24小时格式



我通过这个例子实现了angular 6日期时间选择器(OwlDatetime(:https://stackblitz.com/github/DanielYKPan/owl-examples/tree/date-time-picker?file=src%2Fapp%2Fbasic%2Fbasic.component.html.

我也想将输入格式更改为24小时格式,因为现在正如您在stackblitz中看到的那样,选择器有24小时的格式,但一旦选择了时间,它就会以am/pm显示在输入中。

我尝试过更改输入格式,但没有成功:

<input [owlDateTimeTrigger]="dt"                  [ngModel]="test[key.id] | date: HH:mm" 
[owlDateTime]="dt"  (ngModelChange)="test[key.id]=change($event)" >
<owl-date-time [pickerType]="'timer'"  #dt>

有人能帮忙吗?

首次安装:

npm install ng-pick-datetime-moment moment --save;

如果需要最终依赖关系,请检查安装日志。像@angular/core或@angular/cdk等

然后:定义下一个:

//somefile.ts
static MY_MOMENT_FORMATS = {
parseInput: 'LL LT',
fullPickerInput: 'YYYY-MM-DD HH:mm', /* <---- Here i've rewrited the format */
datePickerInput: 'LL',
timePickerInput: 'LT',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MM YYYY',
};

并添加根app.module

//app.module.ts import {OWL_DATE_TIME_FORMATS, OwlDateTimeModule, OwlDateTimeIntl, OWL_DATE_TIME_LOCALE} from 'ng-pick-datetime';
import {MY_MOMENT_FORMATS} from './.../somefile.ts'; 
...
imports: [
{provide: OWL_DATE_TIME_FORMATS, useValue: MY_MOMENT_FORMATS}, ]
...

仅此而已。

就是一个例子

https://danielykpan.github.io/date-time-picker/#locale-格式化

在"将选择器与MomentJS一起使用"一节中

最新更新