javascript - 在 TypeScript 和 MongoDB 中仅获取没有时间的日期
问题描述
我在 TypeScript 中有以下代码
const EmployeeDetailsSchema: mongoose.Schema = new mongoose.Schema({
employeeId: { type: String },
advance: {
lastAdvanceClosedOn: { type: String },
pending: { type: String },
nextVacation: { type: String },
IquamaStatus: { type: String },
allowedAdvance: { type: Number },
duration: { type: String },
requiredAdvance: { type: Number },
adDate: { type: Date, default: new Date(new Date().getFullYear(),new Date().getMonth() , new Date().getDate()) }}
}
);
在我的数据库表中,adDate如下所示;
日期:2020-03-12T00:00:00.000+00:00
但我想要如下输出;
添加日期 : 12-03-2020
如何在不将“类型”更改为字符串的情况下实现这一点
解决方案
使用 moment.js
moment(<your Date goes here>).format("DD-MM-YYYY")
然后传递值
推荐阅读
- google-cloud-storage - 如何在 terraform 13.5 中将变量传递给 google_storage_bucket_object
- perforce - Perforce:如何查看单个文件的整个历史记录
- python - UnicodeEncodeError:“ascii”编解码器无法在位置 134 编码字符“\xf6”:序数不在范围内(128)
- c++ - 如何将字符串转换为多个 int 值?C++
- c++ - 为什么不是 cmath 的 pow 和 sqrt 模板?
- python - 将类属性设置为 lambda 属性时,如何让 Python 接受每个值?
- jenkins - 如何从 Jenkins 声明式管道替换 Artifactory File Spec “Spec Vars”
- javascript - 如何从 JS 中的 2 个对象数组中找到唯一元素
- r - 如何在我的dashboardHeader() 上放置图像(徽标)?
- java - 双向关系的垃圾收集