我有一个模型类,看起来像:
export class TimeInModel{
//to store only date as --mm/dd/yyy
public date_today:Date;
//to store time as --HH/mm/ss
public time_in:Date;
public check_status:boolen;
constructor(){}
}
从date_today
开始,我只想传递当前日期(mm/dd/yyy(,从time_in
开始,只传递时间(hh/mm/ss(。
我该如何在同一类或组件中执行此操作。
在更彻底地阅读了您的问题之后,我可以为您提供这个答案:
export class TimeInModel {
public date_today: string; // Because Date is a timestamp
public time_in: string; // Same cause
public check_status: boolean;
constructor() {
let today = new Date();
this.date_today = `${today.getDate()}/${today.getMonth() + 1}/${today.getYear()}`;
this.time_in = `${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}`;
}
}