java cron expression to generate a specified time

Package com.information.util.quartz; 

Import the java.text.SimpleDateFormat;
 Import java.util.Date;
 Import java.util.Objects; 

/ ** 
 * date conversion cron expression 
 * @author Administrator 
 * 
 * / 
public  class CronUtils { 

    // "? SS HH dd mm yyyy mM" 
    Private  static  Final SimpleDateFormat SDF = new new SimpleDateFormat ( "SS HH mm dd mM?" ); 

    / ** * 
     * description: date conversion cron expression 
     * @param dATE 
     * @return 
     * / 
    public static String formatDateByPattern(Date date) {
        String formatTimeStr = null;
        if (Objects.nonNull(date)) {
            formatTimeStr = sdf.format(date);
        }
        return formatTimeStr;
    }

    /***
     * convert Date to cron, eg "0 07 10 15 1 ?"
     * @param date  : 时间点
     * @return
     */
    public static String getCron(Date date) {
        return formatDateByPattern(date);
    }
    
}

 

Guess you like

Origin www.cnblogs.com/noire/p/11332559.html