【问题标题】:how i can transform date format in "dd-MM-yyyy" i'm getting this in this format "yyyy-MM-dd" in NestJs我如何在 \"dd-MM-yyyy\" 中转换日期格式 我\在 NestJs 中以这种格式 \"yyyy-MM-dd\" 得到这个
【发布时间】:2022-12-28 18:29:36
【问题描述】:

我如何在“dd-MM-yyyy”中转换日期格式我以这种格式“yyyy-MM-dd”得到这个 这是我实体中的代码

  @IsOptional()
  @ApiProperty({ example: '1999-12-12', nullable: true })
  @Column({ type: 'date', nullable: true })
  birthDate?: Date;

我试图以这种格式转换“dd-MM-yyyy”

【问题讨论】:

    标签: node.js typescript nestjs typeorm


    【解决方案1】:

    toLocaleDateString 在参数中包含所需的区域设置将帮助您。

      transformDate(date: string): string {
        const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
        return new Date(date).toLocaleDateString('en-US', options);
      }
    

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多