NestJS+TypeORM查询MySQL时间与数据库存储值不匹配问题
NestJS + TypeORM 查询MySQL时间字段出现UTC转换偏差问题
我在本地使用NestJS搭配TypeORM查询MySQL数据库中的updated_at和created_at字段。数据库中记录明确以UTC时间存储,但调用find()方法查询后,时间被再次转换为UTC,出现如下时间偏差:
- 本地时间(GMT+7):2024-04-13 12:00:00
- 数据库存储时间:2024-04-13 05:00:00
- find()查询返回时间:2024-04-12 22:00:00
实体定义
@Entity('designs') export class DesignEntity { @PrimaryGeneratedColumn() id: number; @OneToOne(() => ProjectEntity, (project) => project.design) @JoinColumn() project: ProjectEntity; @Column({ type: 'json', nullable: true }) landData: any; @Column({ type: 'json', nullable: true }) settingData: any; @CreateDateColumn() createdAt: Date; @UpdateDateColumn() updatedAt: Date; @DeleteDateColumn() deletedAt: Date; }
查询代码
const design = await this.designService.findOne({ where: { project: { id: proj.id } } }); console.log(design.updatedAt)
内容的提问来源于stack exchange,提问作者Expl0de
相关产品推荐
相关产品推荐

