javascript - 如何将 unix 时间戳转换为 TypeScript 中的日期?

标签 javascript date typescript

在普通的 JavaScript 和 TypeScript 中,我们可以编写以下代码来获取 Date 的 unix 时间戳:

let d = new Date();
const unixtime = d.valueOf();

现在,在 JavaScript 中,我们可以轻松地将 unix 时间戳转换回日期:

d = new Date(unixtime);

但是,在 TypeScript 中,上面的代码会返回一条错误消息:

error TS2554: Expected 0 arguments, but got 1.

那么如何将 unix 时间戳转换为 TypeScript 中的日期?我正在使用 ES6 库

最佳答案

in TypeScript, the above returns an error message:

当前TypeScript没有错误:

enter image description here

修复

将 TypeScript 更新到最新 🌹

关于javascript - 如何将 unix 时间戳转换为 TypeScript 中的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48105329/

相关文章:

javascript - 为什么 Angular 5 Transition 抛出 AppComponent.html :2 ERROR TypeError: Cannot read property 'forEach' of undefined

angular - 使用类装饰器时需要未捕获的反射元数据垫片

Angular 8发出多个http请求并合并所有结果

javascript - 我只想在一些 div 中创建简单的菜单链接?

javascript - Lodash 返回键如果存在,否则返回另一个键

javascript - 仅在某些级别上防止违约

javascript - jQuery 不滚动到 anchor 标记

java - 将字符串时间戳转换为日期

java - 通过字符串变量命名对象

mysql 获取小时/分钟/秒的总和