我尝试在
node
环境中在此代码片段中使用 js-joda:
LocalDateTime.parse(row.date + "T" + row.time)
.atZone(ZoneId.of("America/Los_Angeles"))
.toInstant()
.toEpochMilli()
我收到此错误:
ERROR: unsupported ZoneId:America/Los_Angeles
{
"stack": "Error\n at getRules (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:4395:15)\n at ofId (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:4406:39)\n at of (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:10262:27)\n at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:119:30)\n at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:79:25)\n at map (native)\n at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:79:14)\n at processTicksAndRejections (native)",
"message": "unsupported ZoneId:America/Los_Angeles"
}
我可以在浏览器控制台中正常运行此代码:https://js-joda.github.io/js-joda/:
我需要设置什么才能使其在节点环境中工作?
Js-joda 软件包已被弃用,您可以使用 @js-joda/core 代替
npm i @js-joda/core
和
您需要在文件顶部导入
@js-joda/timezone
,这将启用时区
require('@js-joda/timezone');
那就试试这个吧
LocalDateTime.parse(row.date + "T" + row.time)
.atZone(ZoneId.of("America/Los_Angeles"))
.toInstant()
.toEpochMilli()