cronjob 时间语法"* * * * * *"如下 npm
我想将时间转换为"2017-05-09T01:30:00.123Z"cron 作业时间格式。有库或者方法可以实现吗?
Arm*_*yan 11
const dateToCron = (date) => {
const minutes = date.getMinutes();
const hours = date.getHours();
const days = date.getDate();
const months = date.getMonth() + 1;
const dayOfWeek = date.getDay();
return `${minutes} ${hours} ${days} ${months} ${dayOfWeek}`;
};
const dateText = '2017-05-09T01:30:00.123Z';
const date = new Date(dateText);
const cron = dateToCron(date);
console.log(cron); //30 5 9 5 2
Run Code Online (Sandbox Code Playgroud)
我不知道是否有任何图书馆。但您可以使用简单的日期函数简单地实现它。
var date=new Date("2017-05-09T01:30:00.123Z");
var mins=date.getMinutes();
//mins variable for the 1st * and so on
var secs=date.getSeconds();
var dayofmonth=date.getDate();
var month=date.getMonth();
var dayofweek=date.getDay();
Run Code Online (Sandbox Code Playgroud)
然后,您可以构建一个字符串并在 cron 模块中使用这些值。
| 归档时间: |
|
| 查看次数: |
9302 次 |
| 最近记录: |