PrimeNg日历:用于选择开始日期和时间的默认时间-应该是一天中的开始时间00:00:00

时间:2019-11-25 12:25:59

标签: angular primeng

我正在使用带有两个字段的PrimeNg日历小部件,分别是startDate和endDate。

当前,当选择startDate时,它将显示当前时间的所选日期,但我的要求是,所选时间的开始时间为00:00:00。

当在endDate字段中时,我们正在选择日期,该日期显示的是当前时间的选定日期,但我希望选定的日期是一天中时间的23:59:59。

我正在将Angular 7与primeNg(primefaces)一起使用。

请帮助您解决此问题。

1 个答案:

答案 0 :(得分:0)

您可以使用date对象的setHours,setMinutes和setSeconds方法。 PrimeNg p日历使用日期对象。

是的。 component.ts

import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  date1 = new Date();
  date2 = new Date();
  constructor(){
    this.date1.setHours(0);
    this.date1.setMinutes(0);
    this.date1.setSeconds(0);
    this.date2.setHours(0);
    this.date2.setMinutes(0);
    this.date2.setSeconds(0);
  }
}

Component.html

<div class="ui-g-12 ui-md-4">
        <h3>Start Time</h3>
        <p-calendar [(ngModel)]="date1" [showTime]="true" hourFormat="24"></p-calendar>
    </div>
<br>

<div class="ui-g-12 ui-md-4">
        <h3>End Time</h3>
        <p-calendar [(ngModel)]="date2" [showTime]="true" hourFormat="24"></p-calendar>
</div>

working code

相关问题