Angular 9 时刻时区
Moment Timezone in Angular 9
目前,我将 Angular 项目表单 8
升级到 9
。
该项目在 package.json
中使用 "@types/moment-timezone": "^0.5.30"
现在这个包已经被弃用了。 https://www.npmjs.com/package/@types/moment-timezone
当我 运行 项目 ng serve
时,它显示此错误消息
user.model.ts:3:25 - error TS7016: Could not find a declaration file for module 'moment-timezone'. '/home/bunthai/sftp/upgrade/projectg/ui/ctr/node_modules/moment-timezone/index.js' implicitly has an 'any' type.
Try `npm install @types/moment-timezone` if it exists or add a new declaration (.d.ts) file containing `declare module 'moment-timezone';`
import * as moment from 'moment-timezone';
~~~~~~~~~~~~~~~~~
如何处理这个问题?
您需要删除此导入,然后手动导入您想要的时区,例如:
import moment from "moment";
import "moment/locale/fr";
moment.locale('fr')
如果您不导入其他时区,您将获得默认的 nodeJS 服务器时区。如果你想要另一个,你需要导入它并使用它。
我找到了解决方案:
在我的例子中,从 import * as moment from 'moment-timezone'
更改为 const moment = require('moment-timezone');
目前,我将 Angular 项目表单 8
升级到 9
。
该项目在 package.json
中使用 "@types/moment-timezone": "^0.5.30"
现在这个包已经被弃用了。 https://www.npmjs.com/package/@types/moment-timezone
当我 运行 项目 ng serve
时,它显示此错误消息
user.model.ts:3:25 - error TS7016: Could not find a declaration file for module 'moment-timezone'. '/home/bunthai/sftp/upgrade/projectg/ui/ctr/node_modules/moment-timezone/index.js' implicitly has an 'any' type.
Try `npm install @types/moment-timezone` if it exists or add a new declaration (.d.ts) file containing `declare module 'moment-timezone';`
import * as moment from 'moment-timezone';
~~~~~~~~~~~~~~~~~
如何处理这个问题?
您需要删除此导入,然后手动导入您想要的时区,例如:
import moment from "moment";
import "moment/locale/fr";
moment.locale('fr')
如果您不导入其他时区,您将获得默认的 nodeJS 服务器时区。如果你想要另一个,你需要导入它并使用它。
我找到了解决方案:
在我的例子中,从 import * as moment from 'moment-timezone'
更改为 const moment = require('moment-timezone');