Get the number of days, weeks, and months, since Epoch in Java

前端 未结 7 782
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 18:05

I\'m trying to get the number of days, weeks, months since Epoch in Java.

The Java Calendar class offers things like calendar.get(GregorianCalendar.DAY_OF_YEAR), or

7条回答
  •  日久生厌
    2020-12-01 18:31

    Long currentMilli = System.currentTimeMillis();
    Long seconds = currentMilli / 1000;
    Long minutes = seconds / 60;
    Long hours = minutes / 60;
    Long days = hours / 24;
    System.out.println("Days since epoch : "  + days);
    

    or

    System.out.println("Days since epoch : "  + ((int) currentMilli / 86400000));
    

提交回复
热议问题