node.js - 如何从猫鼬中的日期类型中检索毫秒?
问题描述
我正在尝试做一个简单的应用程序,由于我是初学者,我正在努力检索保存在我的猫鼬模式中的日期并将其转换为毫秒。
首先,在我的前端,我想保存输入中的日期:IMAGE
这是它在我的数据库中的保存方式:图像 格式:2020-01-01T00:00:00.000+00:00
当我返回前端计算月份时,我希望以毫秒为单位。如果我将数据类型更改为“数字”,它就可以工作。但是,我不能再从输入中插入日期类型。
这是我的架构:
const mongoose = require("mongoose");
const EmployeeSchema = new mongoose.Schema({
employeeName: {
type: String,
required: true,
},
employeeShift: {
type: String,
required: true,
},
employeeStartDay: {
type: Date,
required: true,
},
});
const Employee = mongoose.model("Employee", EmployeeSchema);
module.exports = Employee;
我的前端:
{employeeList.map((val, key) => {
const month = 1000 * 60 * 60 * 24 * 30;
const startDate = val.employeeStartDay;
const finalDate = date.getTime();
const months = Math.floor(-(startDate - finalDate) / month);
const workingDaysToBeUsed = Math.floor(months * 1.166);
return (
<div>
<table>
<tr>
<th>Specialist</th>
<th>Schedule</th>
<th>Start Day</th>
<th>months passed</th> {/*months passed*/}
<th>Days used</th>
<th>Days accumulated</th>
</tr>
<tr>
<td>{val.employeeName}</td>
<td>{val.employeeShift}</td>
<td>{startDate}</td>
<td>{months}</td>
<td>{}</td>
<td>{workingDaysToBeUsed}</td>
</tr>
</table>
</div>
);
})}
如果我尝试 startDate.getTime() 我收到 startDate.getTime 不是函数的错误消息,这是我不明白的。
我会很感激一些帮助。
解决方案
推荐阅读
- python - 如何在 pyspark 中使用“不存在”的 SQL 条件?
- slickgrid - 光滑的网格值未填充在网格中
- google-bigquery - 如何将 powerbi 连接到 bigquery 或 bigquery 到 powerbi
- android - 当布局拆分为多个文件时,如何将视图模型添加到布局?
- html - 设置 HTML 输入的语言
- swift - 为什么在导入模块中使用函数时 Swift 多线程效率要低得多?
- python - Python SQLite 删除,其中值为“无”
- ios - 如何维护 Firebase 中 2 个表的关系?
- c# - 如何配置正则表达式以跟踪缺少版权和许可标头
- angular - 转译的 Angular 4 文件未在 Web 浏览器上呈现