MySQL日期时间列正确保存,但在检索时再次转换为UTC

inn*_*83r 5 mysql node.js typeorm

我正在使用 typeorm 0.2.18 版,并且我有一个带有 CreateDateColumn 的模型,当我保存模型时,它会保存正确的 UTC 时间(我在 EST 中)。但是,当我从数据库中检索记录时,日期再次转换为 UTC。我还就此打开了一个 github 问题:https : //github.com/typeorm/typeorm/issues/4261

我试图将列更改为“日期时间”列,它似乎总是再次将检索到的日期转换为 UTC,即使在数据库中它是 UTC。

[...]
@Entity()
export class Book{
    @PrimaryGeneratedColumn()
    BookId: number;

    @Column()
    BookName: string;

    @Column()
    Genre: string;

    @CreateDateColumn()
    DateAdded: Date;
}

Run Code Online (Sandbox Code Playgroud)

我没有收到任何错误,但检索到的日期总是再次转换为 UTC。

小智 2

尝试将时区设置为“Z” connection options。默认情况下它设置为“本地”。

timezone: "Z"

https://github.com/typeorm/typeorm/issues/2939#issuecomment-1066141408