【发布时间】:2020-09-28 08:35:06
【问题描述】:
我想知道是否可以在打字稿中将Date() 转换为moment().tz("America/Los_Angeles").format();
我试过了
import { MomentTimezone } from 'moment-timezone';
const moment : MomentTimezone = new MomentTimezone(Date(), "America/Los_Angeles");
但我有这个错误:
S2693: 'MomentTimezone' only refers to a type, but is being used as a value here
做的时候
import * as moment from "moment-timezone";
let now = moment();
我有这个错误:
TS2349: This expression is not callable. Type 'typeof import("C:/Users/sandro/IdeaProjects/booking/node_modules/moment/moment.d.ts")' has no call signatures.
和
const moment: MomentTimezone = {date: Date(), timezone: 'America/Los_Angeles'};
但我得到了
TS2322: Type '{ date: string; timezone: string; }' is not assignable to type 'MomentTimezone'. Object literal may only specify known properties, and 'date' does not exist in type 'MomentTimezone'
【问题讨论】:
-
请阅读以下文章,了解如何提出一个好问题:stackoverflow.com/help/how-to-ask
标签: javascript node.js typescript momentjs moment-timezone