Convert Current date to integer

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

    Try This

    Calendar currentDay= Calendar.getInstance();
    int currDate= currentDay.get(Calendar.DATE);
    int currMonth= currentDay.get(Calendar.MONTH);
    int currYear= currentDay.get(Calendar.YEAR);
    System.out.println(currDate + "-" +  currMonth + "-" + currYear);
    

    an alternative way using LocalDate.

    LocalDate today = LocalDate.now();
    int currentDate= today.getDayOfMonth();
    int currentMonth= today.getMonthValue();
    int currentYear= today.getYear()
    

提交回复
热议问题