简体   繁体   中英

How to convert given time to cron expression using quartz api in java?

How to convert Given time to cron expression.

ie example given time

scheduled day="mon,tue" time="11.00" timeinterval="3" type="Weekly" to cron expression.

A solution to this question will really appreciated and very helpful for me.

How about writing simple function using

public class T {

    public static void main(String[] args) throws ParseException {
        LocalDateTime dateTime = LocalDateTime.now();

        System.out.println(toCron(String.valueOf(dateTime.getMinute()),
                String.valueOf(dateTime.getHour()),
                String.valueOf(dateTime.getDayOfMonth()),
                String.valueOf(dateTime.getMonth()),
                String.valueOf(dateTime.getDayOfWeek()), String.valueOf(dateTime.getYear())));
    }


    public static String toCron(final String mins, final String hrs, final String dayOfMonth, final String month, final String dayOfWeek, final String year) {
        return String.format("%s %s %s %s %s %s", mins, hrs, dayOfMonth, month, dayOfWeek, year);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM