我有问题。
我正在尝试通过* .js文件将某些数据从一张表彼此“传输”。除了一件事,一切都进行得很好。此功能向我显示:
Error: Timezone "gmt+0200" is not recognized
这是我的职责
async function submitCompletationCG(database, ulogin, idc) {
await connectToSpecificDatabase(database);
const AC_ID = `SELECT * FROM public.cg_actualcompletations WHERE UserLogin = '`+ulogin+`';`;
let AC_IDs = await client.query(AC_ID);
const ACC_ID = `SELECT * FROM public.cg_actualcompletationscondensed WHERE UserLogin = '`+ulogin+`';`;
let ACC_IDs = await client.query(ACC_ID);
const DEPOT = `SELECT * FROM public.cg_actualdepots WHERE UserLogin = '`+ulogin+`';`;
let DEPOTs = await client.query(DEPOT);
let depot_from, depot_to, code_from, code_to;
for(let Depot of DEPOTs.rows) {
depot_from = Depot.depot_from;
depot_to = Depot.depot_to;
code_from = Depot.code_from;
code_to = Depot.code_to;
}
for(let Completation of ACC_IDs.rows) { //Transfer all Completations Condensed
const ACC_Copy = `INSERT INTO public.cg_completationscondensed(
id_c, userlogin, barcode, quantity, adate)
VALUES ('`+idc+`', '`+ulogin+`', '`+Completation.barcode+`', '`+Completation.quantity+`', '`+Completation.adate+`');`;
await client.query(ACC_Copy);
const ACC_Delete = `DELETE FROM public.cg_actualcompletationscondensed
WHERE id = `+Completation.id+`;`;
await client.query(ACC_Delete);
}
for(let Completation of AC_IDs.rows) { //Transfer all Completations
const AC_Copy = `INSERT INTO public.cg_completations(
id_c, userlogin, barcode, quantity, adate)
VALUES ('`+idc+`', '`+ulogin+`', '`+Completation.barcode+`', '`+Completation.quantity+`', '`+Completation.adate+`');`;
await client.query(AC_Copy);
const AC_Delete = `DELETE FROM public.cg_actualcompletations
WHERE id = `+Completation.id+`;`;
await client.query(AC_Delete);
}
const SUB_UArch = `INSERT INTO public.cg_userarch(
userlogin, id_c, depot_from, depot_to, code_from, code_to)
VALUES ('`+ulogin+`', '`+idc+`', '`+depot_from+`', '`+depot_to+`', '`+code_from+`', '`+code_to+`');`;
await client.query(SUB_UArch);
const SUB_DKill = `DELETE FROM public.cg_actualdepots WHERE UserLogin = '`+ulogin+`';`;
await client.query(SUB_DKill);
return true;
}
我可以在角度文件中的某个地方设置时区吗?还是数据库有问题?忘了说我正在使用PostgreSQL。 ADate列的类型为“无时区的时间戳”,之前为“有时区的时间戳”,但我认为这会导致问题,因此我将其更改。
我在此行遇到此问题:
for(let Completation of ACC_IDs.rows) { //Transfer all Completations Condensed
const ACC_Copy = `INSERT INTO public.cg_completationscondensed(
id_c, userlogin, barcode, quantity, adate)
VALUES ('`+idc+`', '`+ulogin+`', '`+Completation.barcode+`', '`+Completation.quantity+`', '`+Completation.adate+`');`;
await client.query(ACC_Copy);
const ACC_Delete = `DELETE FROM public.cg_actualcompletationscondensed
WHERE id = `+Completation.id+`;`;
await client.query(ACC_Delete);
}
和下一个for循环中,因为日期上也有操作。
答案 0 :(得分:0)
我解决了这个问题。我在互联网上的任何地方都找不到答案,所以我自己做。我在for循环的开头添加了这两行:
let date = new Date(Completation.adate);
date = date.toLocaleDateString() + " " + date.toLocaleTimeString();
,然后将数据库查询更改为:
const ACC_Copy = `INSERT INTO public.cg_completationscondensed(
id_c, userlogin, barcode, quantity, adate)
VALUES ('`+idc+`', '`+ulogin+`', '`+Completation.barcode+`', '`+Completation.quantity+`', '`+date+`');`;
现在终于可以正常工作了!