mongoose-timezone
一个mongoose插件,用于规范存储的日期时区。默认情况下,mongo日期以UTC格式存储,如果服务器存放在其它时区,则显示会有差别。该插件用于渲染服务器所在时区的时间。
A mongoose plugin used to standardize the stored date and time zone. By default, mongo dates are stored in UTC format, but if the server is stored in another time zone, the display may differ. This plugin is used to render the time zone of the server.
Install
by npm
npm install @michaelray/mongoose-timezone --save
by yarn
yarn add @michaelray/mongoose-timezone
Usage
import mongoose from "mongoose";
// @ts-ignore
import {timeZone} from "@michaelray/mongoose-timezone";
// 全局插件
mongoose.plugin(timeZone);
// @ts-ignore
import { baseSchema } from "@michaelray/mongoose-timezone/baseSchema";
const schemaData = new Schema({
date: Date,
subDocument: {
subDate: {
type: Date,
},
},
...baseSchema // add like this
})
mongoose-timezone是一个针对mongoose的插件,它确保日期在存储时考虑服务器的时区,避免因默认使用UTC格式导致的显示差异。安装可通过npm或yarn,然后全局应用到mongoose模型中。基础Schema示例展示了如何在文档中包含时间戳信息。
2443

被折叠的 条评论
为什么被折叠?



