Skip to content
大纲

判断是否达到指定时间

通常用来做定时任务,达到指定时间后更改视图等操作。

语法

js
import { isScheduled } from 'warbler-js';
const result = isScheduled(date);

参数

  • date (String) : 指定日期,指定日期,格式为"YYYY-MM-DD HH:mm:ss"。

返回值

Booleantrue 达到指定时间, false 没有达到指定时间。

源码

js
const isScheduled = (date) => {
  const date1 = new Date();
  const date2 = new Date(Date.parse(date));
  return date1 > date2;
};

例子

js
import { isScheduled } from 'warbler-js';
//测试日期为2021-10-18
const result1 = isScheduled('2021-10-17 00:00:00');
const result2 = isScheduled('2021-10-19 00:00:00');
console.log(result1); //=> true
console.log(result2); //=> false

添加版本

1.2.0

Released under the MIT License.