Android examples for java.util:Day
get Offset Day
//package com.java2s; import java.util.Calendar; public class Main { public static int getOffsetDay(long milliseconds1, long milliseconds2) { Calendar calendar1 = Calendar.getInstance(); calendar1.setTimeInMillis(milliseconds1); Calendar calendar2 = Calendar.getInstance(); calendar2.setTimeInMillis(milliseconds2); int y1 = calendar1.get(Calendar.YEAR); int y2 = calendar2.get(Calendar.YEAR); int d1 = calendar1.get(Calendar.DAY_OF_YEAR); int d2 = calendar2.get(Calendar.DAY_OF_YEAR); int maxDays = 0; int day = 0; if (y1 - y2 > 0) { maxDays = calendar2.getActualMaximum(Calendar.DAY_OF_YEAR); day = d1 - d2 + maxDays;/* w w w .ja v a 2 s. c o m*/ } else if (y1 - y2 < 0) { maxDays = calendar1.getActualMaximum(Calendar.DAY_OF_YEAR); day = d1 - d2 - maxDays; } else { day = d1 - d2; } return day; } }