错误:无法识别时区"gmt+0200"



我有问题。

我正在尝试通过 *.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;
}

我应该在Angular Files的某个地方设置时区吗?还是数据库的问题?忘了说我正在使用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);
  }

和下一个循环,因为日期也有操作。

您将Date()类型/值的结果注入查询。将其转换为ISO字符串解决我的问题。

我解决了这个问题。我在互联网上的任何地方都找不到答案,所以我自己做。我在for循环的开头添加了这两条线:

let date = new Date(Completation.adate);
    date = date.toLocaleDateString() + " " + date.toLocaleTimeString();

然后将DB查询更改为:

const ACC_Copy = `INSERT INTO public.cg_completationscondensed(
                      id_c, userlogin, barcode, quantity, adate)
                      VALUES ('`+idc+`', '`+ulogin+`', '`+Completation.barcode+`', '`+Completation.quantity+`', '`+date+`');`;

现在效果很好,终于!

相关内容

  • 没有找到相关文章

最新更新