PostgreSQL 輸出的時(shí)間戳格式與 Javascript 時(shí)間戳格式不同
我無(wú)法將 SQL 的結(jié)果綁定到我的模型Javascript /Typescript。在我的模型中,我有一個(gè)created_atwith types of的屬性Date。當(dāng)我在 Postgres SQL 語(yǔ)句中使用 JSON 函數(shù)來(lái)避免關(guān)系的重復(fù)父行時(shí),我將獲得不同格式的時(shí)間戳。這是一個(gè)簡(jiǎn)單的例子SELECT a.*, ( SELECT ROW_TO_JSON(profile) FROM ( SELECT * FROM profile p WHERE p.account_id = a.id ) profile ) AS profile FROM account a WHERE a.id = 16這是 JSON 格式的結(jié)果{ "id":16, "email":"test@gmail.com", "password":"$password", "role_id":0, "created_at":"2020-04-01T22:03:44.324Z", "profile":{ "id":8, "username":"firmanjml", "gender":0, "bio":null, "avatar":"www.firmanjml.me/test.jpg", "account_id":16, "created_at":"2020-04-02T06:03:44.32498" }}我注意到來(lái)自帳戶表的父行在末尾有 Z,created_at而轉(zhuǎn)換為 JSON 的子表具有不同的時(shí)間戳格式。有沒(méi)有辦法可以使所有時(shí)間戳都采用Javascript格式?查詢以創(chuàng)建模式和插入數(shù)據(jù)CREATE TABLE "account"( id SERIAL primary key, email varchar(50) not null, password varchar(50) not null, role_id int2 default 0 not null, created_at timestamp default now() not null);CREATE TABLE "profile"( id SERIAL primary key, username varchar(50) not null, gender int2 not null, bio varchar(50), avatar varchar(50), account_id integer not null REFERENCES account (id), created_at timestamp default now() not null);INSERT INTO "account" (email,"password","role_id",created_at) VALUES ('test@gmail.com','$password',0,'2020-04-02 06:03:44.324');INSERT INTO "profile" (username,gender,bio,avatar,account_id,created_at) VALUES ('fimrnajml',0,NULL,'www.firmanjml.me/test.jpg',1,'2020-04-02 06:03:44.324');
查看完整描述