Here you can find the source of daysSinceTimestamp(long timestamp)
Parameter | Description |
---|---|
timestamp | the start milliseconds from which start to count days |
public static long daysSinceTimestamp(long timestamp)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { /**/*from w w w . ja v a 2 s .com*/ * Determine days difference since timestamp to current time * if timestamp is equal to Long.MAX_VALUE then return Long.MAX_VALUE * * @param timestamp the start milliseconds from which start to count days * @return numbers of days, if negative indicates days in the future beyond * passed timestamp */ public static long daysSinceTimestamp(long timestamp) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long nowTime = cal.getTimeInMillis(); long dayTime = 24 * 60 * 60 * 1000; long days; if (timestamp == Long.MAX_VALUE) { days = Long.MAX_VALUE; } else { cal = Calendar.getInstance(); cal.setTime(new Date(timestamp)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long tsWithoutTime = cal.getTimeInMillis(); long spanTime = nowTime - tsWithoutTime; days = spanTime / dayTime; } return days; } }