javascript - 数据格式错误
问题描述
我正在尝试将数据从我的后端插入到 MongoDb。例如,如果我想插入“2021-06-03”,我将得到“2021-06-02T21:00:00.000+00:00”。模型 :
const organizerSchema = new mongoose.Schema({
description: { type: String, required: true },
duration: { type: Number },
location: { type: String },
date: { type: Date, default: Date.now },
和路线:
const { description } = req.body;
const { date } = req.body;
const { location } = req.body;
const { duration } = req.body;
const newAdd = new Add({
description,
date,
location,
duration,
});
解决方案
为什么不尝试使用 moment( moment().unix() )将其保存为 unix?这是一个数字,您应该能够轻松地将其转换回日期。
否则使用时刻将其转换为正确的时区
时刻(日期).utcOffset('+0300').format(格式)
推荐阅读
- php - 如何将默认的 php 代码重写为有效的回显行输出?
- iframe - 从安全角度将小部件嵌入网页的最佳实践
- keycloak - Keycloak - 基于资源的角色和范围基本身份验证
- html - 模板检查未发生/更改检测器未运行(角度)
- python - 保存为 pdf 时的 hist2d 条纹
- java - 如何在单元测试中使用不同的静态内容?
- amazon-web-services - S3 复制 Terraform 应用加密错误
- javascript - 如何使用 ipfs-http-client API 通过 Infura 的网关为 IPFS 固定哈希
- elasticsearch - 是否可以在索引而不是纯文本上使用 _analyze ElasticSearch 端点?
- android - 如何解决android原生应用程序中的意图重定向?