首页 > 解决方案 > 如何将日期格式更改为“dd / mm / yy”?

问题描述

虽然我在javascript中使用'toISOString()',但它记录在照片2中。我如何更改这种格式。

注意:我正在使用 AngularJs。图 1 是list.component.ts

附加文件:

图片1

图 2

图片1:

formatDate(e) {
  var convertDate = new
  Date(e.target.value).toISOString().substring(0, 10);
  this.studentForm.get('dob').setValue(convertDate, {
    onlyself: true
  })
}

标签: javascripttypescript

解决方案


您可以intl像这样使用 JS 提供的对象 -

const date = new Date();
new Intl.DateTimeFormat('en-GB').format(date);

推荐阅读