Convert Current date to integer

前端 未结 12 884
轮回少年
轮回少年 2020-12-05 04:35

I want to convert the current date to integer value. By default, it returns long. When I try to convert long to integer, and afterwards I convert the integer value to date,

12条回答
  •  [愿得一人]
    2020-12-05 04:46

    Java Date to int conversion:

    public static final String DATE_FORMAT_INT = "yyyyMMdd";
    
    public static String format(Date date, String format) {
        return isNull(date) ?  
        null : new SimpleDateFormat(format).format(date);
    }
    
    public static Integer getDateInt(Date date) {
        if (isNull(date)) {
            throw new IllegalArgumentException("Date must not be NULL");
        }
    
        return parseInt(format(date, DATE_FORMAT_INT));
    }
    

提交回复
热议问题