如何使用FormBuilder获取angular 8中的系统日期

如何使用FormBuilder获取angular 8中的系统日期,angular,typescript,Angular,Typescript,我使用FormBuilder创建了一个表单,我需要用以下内容自动填充它: this.creationDate = moment().format(DATE_TIME_FORMAT); 创建时的系统日期和时间,而不是dd//mm/yyyy-->: 如果要设置创建日期,可能不希望用户能够编辑该创建日期。我建议不要在表单字段中提供该选项,即使您计划禁用该表单字段。您可能希望在博客中设置属性构造函数,只需添加this.creationDate=moment().format(DATE\u TIME\u

我使用FormBuilder创建了一个表单,我需要用以下内容自动填充它:

this.creationDate = moment().format(DATE_TIME_FORMAT);
创建时的系统日期和时间,而不是dd//mm/yyyy-->:


如果要设置创建日期,可能不希望用户能够编辑该创建日期。我建议不要在表单字段中提供该选项,即使您计划禁用该表单字段。您可能希望在
博客中设置属性
构造函数,只需添加
this.creationDate=moment().format(DATE\u TIME\u format)
即可。如果您真的想将其添加到表单中,可以使用

this.fb.control(新日期())
然后禁用它,这样用户就不能更改他们所说的创建日期


注意:这只适用于其唯一任务是创建新博客帖子的表单。对于编辑现有博客文章,您将始终希望从正在使用的任何持久存储中读取创建日期。

为什么要在客户端执行此操作?让服务器设置它实际创建的时间。谢谢,因为我想用当前日期填充它,而不是在表单中看到:dd/mm/yyy-:--我不明白你想说什么。
  private createFromForm(): IBlog {
return {
  ...new Blog(),
  id: this.editForm.get(['id']).value,
  creationDate:
    this.editForm.get(['creationDate']).value != null ? moment(this.editForm.get(['creationDate']).value, DATE_TIME_FORMAT) : undefined,
  title: this.editForm.get(['title']).value,
  imageContentType: this.editForm.get(['imageContentType']).value,
  image: this.editForm.get(['image']).value,
  appuserId: this.editForm.get(['appuserId']).value,
  communityId: this.editForm.get(['communityId']).value
};
}