【发布时间】:2020-05-31 01:52:08
【问题描述】:
我有一个如下所示的 DTO:
class PersonDto {
readonly name: string;
readonly birthDate: Date;
}
我的 NestJs 控制器方法如下所示:
@Post
create(@Body() person: PersonDto) {
console.log("New person with the following data:", person);
// more logic here
}
发布的 JSON 数据具有 birthDate 作为字符串:"2020-01-15"。如何将此字符串转换为 JavaScript Date 对象?我想将@IsDate 类验证添加到PersonDto,但目前这会失败。
【问题讨论】:
标签: javascript json date nestjs