【问题标题】:How do I change the date format to "dd / mm / yy"? [duplicate]如何将日期格式更改为“dd / mm / yy”? [复制]
【发布时间】:2021-01-19 10:05:43
【问题描述】:

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

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

其他文件:

picture 1

picture 2

图一:

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

【问题讨论】:

  • 请发布代码,而不是代码图像。至于你的问题:这意味着你有一个 Date 对象,格式化这些是一个已解决的问题。并且您可以随时使用getMonth() 之类的方法自己编写字符串。

标签: javascript typescript


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    相关资源
    最近更新 更多