PrimeNG - 在时间选择器组件中设置值

PrimeNG - set value in time-picker component

我使用了 PrimeNG 的日历组件,我使用 timeOnly 属性 只显示时间,我有一个像 12:10.

这样的字符串

我想将此字符串设置到日历中,是否需要将其转换为日期或有其他方法吗?

<p-calendar [timeOnly]="true" formControlName="ms" (onSelect)="compareTwoTimesM()" placeholder="hh:mm">

是的,您可以创建一个日期并像这样设置它的小时和分钟:

let input = '12:10';
let tmp = input.split(':');
this.ms = new Date();
this.ms.setHours(parseInt(tmp[0]));
this.ms.setMinutes(parseInt(tmp[1]));