typescript - 如何在 Typescript 中获取当前日期前 3 个月的日期对象
问题描述
我正在尝试从当前日期起 3 个月之前获取日期对象,就像这样。
toDate = new Date();
fromDate = this.toDate.getMonth() - 3;
但这fromDate
只是一个数字。每次我想从当前日期开始 3 个月之前获取日期。但这仅显示了这样的选项。
this.fromDate = (this.toDate.getMonth() - 3).toLocaleString()
是否有可能在 3 个月之前获得日期对象?
解决方案
也许我可以帮忙
toDate = new Date();
month = toDate.getMonth() -3;
newDate = new Date(toDate.setMonth(month));
推荐阅读
- vb.net - vb.net Task.Factory 需要多个任务吗?
- javascript - 从 textarea JS 函数中删除尾随字母
- java - Java 中的指数分布不正确 - 值太小?
- c# - 使用 C# 记录错误
- python - Numpy issubdtype 给出“TypeError:数据类型不理解”
- powershell - 自动化 SQL DataWareHouse(暂停和恢复)
- java - 在 Java 中将 singed int 转换为 uint
- arrays - MATLAB 上 for 循环中的数组索引
- reactjs - 'react-i18next: withNamespaces is not a function' 测试时
- angular - Angular中的双向数据绑定没有自动完成功能?