获取昨天的日期JavaScript 版本
const yesterday = ((d) => new Date(d.setDate(d.getDate() - 1)))(new Date());// Orconst yesterday = new Date(new Date().valueOf() - 1000 * 60 * 60 * 24);
TypeScript 版本
const yesterday: Date = ((d) => new Date(d.setDate(d.getDate() - 1)))(new Date());// Orconst yesterday: Date = new Date(new Date().valueOf() - 1000 * 60 * 60 * 24);
初始化当前日期但将时间设置为午夜JavaScript 版本
const midnightOfToday = () => new Date(new Date().setHours(0, 0, 0, 0));
TypeScript 版本
const midnightOfToday = (): Date => new Date(new Date().setHours(0, 0, 0, 0));
对日期数组进行排序JavaScript 版本
// `arr` 是一个包含 `Date` 项的数组const sortDescending = (arr) => arr.sort((a, b) => a.getTime() > b.getTime());const sortAscending = (arr) => arr.sort((a, b) => a.getTime() < b.getTime());
TypeScript 版本
const sortDescending = (arr: Date[]): Date[] => arr.sort((a, b) => a.getTime() - b.getTime());const sortAscending = (arr: Date[]): Date[] => arr.sort((a, b) => b.getTime() - a.getTime());
推荐阅读
- 啪嗒砰3金手指代码,啪嗒砰3快速升级金手指
- 北方萝卜的储存方法 储藏胡萝卜的常用方法
- vivoy3s有没有快充 vivoy3s有没有闪充
- 临沂职业技术学院2021招生简章 临沂职业学院招生代码2022
- 鸡用兽药经典配方 鸡养殖常用的中兽药配方
- tell的用法和固定搭配 常用搭配推荐
- 电脑宽带连接错误代码678怎么办 电脑网络连接错误代码678该怎么解决
- 这样修剪更符合审美「论述常用的修剪手法」
- 用echo输出html语言中a如何加target属性 target属性作用
- 计算机常用数制有哪些 计算机常用数制解释