使用顯示當前時間 ng-forms
<input
type="time"
class="form-control"
path="time"
formControlName="time"
[ngClass]="{'is-invalid': submitted && f.time.errors}"
/>
uj5u.com熱心網友回復:
也試試這個
您可以使用 Angular2 日期管道來顯示 JavaScript 日期物件。檢查檔案(鏈接)以獲取您正在尋找的正確格式。
解決方案 1:
@Component({
selector: 'date-pipe',
template: `<div>
<p>Today is {{today | date}}</p>
<p>Or if you prefer, {{today | date:'fullDate'}}</p>
<p>The time is {{today | date:'jmZ'}}</p>
<p>Finally the date and time is {{today | date:'short'}}</p>
</div>`
})
export class DatePipeComponent {
today: number = Date.now();
}
解決方案 2:
{{date | date:'yyyy-MM-dd'}}
解決方案 3:
import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction(){
this.date=new Date();
let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/414709.html
標籤:
