我想使用html中的ngx-material-timepicker更新时间。因此,当我选择时间时,格式为上午03:20,我希望在上午03:20
我将数据转换为12小时格式,但无法正常工作
TS代码
convert24To12HourFormat(time): string {
let timeArray = time.split(":");
let timeIn12HourFormat = "";
if (parseInt(timeArray[0]) <= 12) {
timeIn12HourFormat += time + " AM";
}
else {
var newhh = (timeArray[0] - 12) + "";
if (parseInt(newhh) < 10) {
newhh = "0" + newhh;
}
timeIn12HourFormat = newhh + ":" + timeArray[1];
timeIn12HourFormat += " PM";
}
return timeIn12HourFormat;
}
HTML代码
<div *ngIf="editable == true">
<input [ngxTimepicker]="starttime" class="form-control" [(ngModel)]="eventStartTime" name="eventStartTime" placeholder={{eventStartTime}} (ngModelChange)="fieldsChanged();">
<ngx-material-timepicker #starttime ></ngx-material-timepicker>
</div>
<b *ngIf="editable == false">{{eventStartTime}}</b>
</div>
预期输出03:20 AM 实际输出03:20 am