Convert Current date to integer

前端 未结 12 908
轮回少年
轮回少年 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:52

    Do you need something like this(without time)?

    public static Integer toJulianDate(Date pDate) {
    if (pDate == null) {
      return null;
    }
    Calendar lCal = Calendar.getInstance();
    lCal.setTime(pDate);
    int lYear = lCal.get(Calendar.YEAR);
    int lMonth = lCal.get(Calendar.MONTH) + 1;
    int lDay = lCal.get(Calendar.DATE);
    int a = (14 - lMonth) / 12;
    int y = lYear + 4800 - a;
    int m = lMonth + 12 * a - 3;
    return lDay + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
    }
    

提交回复
热议问题