首页 > 解决方案 > 如何在没有时间戳的mongodb集合中保存文档

问题描述

请看看这个日期功能

let tomorrowDate = new Date();
console.log('tomorrowDate',tomorrowDate ) // it returns D-1th date  
tomorrowDate = tomorrowDate.setDate(tomorrowDate.getDate() + 1);
tomorrowDate = new Date(tomorrowDate);
tomorrowDate = tomorrowDate.toISOString().split("T")[0];
tomorrowDate = new Date(tomorrowDate);

如果我明天不重新启动我的开发服务器在 00:00 时选择 D-1 日,我将面临此代码的问题,假设今天是 2020 年 3 月 11 日 00:00 时新日期应该是 2020-03- 12T...Z 但在 00:00 时 new Date() 返回 2020-03-11 为什么会这样???如果我想删除时间戳并且只想保存日期,我尝试拆分 T 但此函数仍将 T00:00:00.000Z 添加为时间戳。

标签: node.jsmongodbdatetime

解决方案


推荐阅读