How to convert general time to cronjob time using nodejs?
cron, node.js
Solution
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
Problem
A cronjob time syntax such as `"* * * * * *"` followed cron npm I want convert time from `"2017-05-09T01:30:00.123Z"` to cron job time format. Have library or method can implement it?