Skip to content

TypeScript 时间戳 && 日期

L edited this page Mar 24, 2019 · 4 revisions

获得目标时间的最后一秒

export class TimeHelper {
    //获得目标时间的最后一秒
    static getLastTimeOfDate(time) {
        var timestamp = time.setHours(23,59,59,999);
        // 根据时间戳timestamp计算time
        time.setTime(timestamp);
    }
}

获得当天的起始时间和结束时间

[moment().startOf('days').toDate(), 
moment().endOf('days').toDate()]
defaultRanges = {
  '今天': [moment().startOf('days').toDate(), moment().endOf('days').toDate()],
  '上一周': [moment().subtract(7, 'days').startOf('days').toDate(), moment().endOf('days').toDate()],
  '上一月': [moment().subtract(1, 'months').startOf('days').toDate(), moment().endOf('days').toDate()],
};

参考资料

How to get start and end of day in Javascript?
javascript时间戳和日期字符串相互转换

Clone this wiki locally