Skip to content

概述

让函数有类型提示的方法

工具方法

比较目标时间+1个月之后是否大于当前时间

ts
function isExpired(endTimeStr: string): boolean {
    // 解析原始结束时间
    const endTime = new Date(endTimeStr);
    
    // 获取一个月后的时间
    const endTimePlusOneMonth = new Date(endTime);
    endTimePlusOneMonth.setMonth(endTimePlusOneMonth.getMonth() + 1);
    
    // 获取当前时间
    const currentTime = new Date();
    
    // 如果当前时间大于结束时间加一个月,返回 true
    return currentTime > endTimePlusOneMonth;
}