map对象中的值为Date类型的时间,将时间戳转换
时间: 2024-05-12 10:15:12 浏览: 197
将 `Date` 类型的时间转换为时间戳可以使用 `getTime()` 方法,例如:
```javascript
const map = new Map();
const date = new Date();
map.set('time', date);
const timestamp = map.get('time').getTime();
console.log(timestamp);
```
如果需要将时间戳转换为 `Date` 类型的时间,可以使用 `new Date(timestamp)` 方法,例如:
```javascript
const timestamp = 1621456156000;
const date = new Date(timestamp);
console.log(date);
```
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)