I have several documents and its created time is in milliseconds. I need to separate them as today, yesterday, last 7 days, last 30 days, more than 30 days.
I used the following code: convertSimpleDayFormat(1347022979786);
public static String convertSimpleDayFormat(Long val) { long displayTime = System.currentTimeMillis() - val; displayTime = displayTime/86400000; String displayTimeVal = ""; if(displayTime <1) { displayTimeVal = "today"; } else if(displayTime<2) { displayTimeVal = "yesterday"; } else if(displayTime<7) { displayTimeVal = "last7days"; } else if(displayTime<30) { displayTimeVal = "last30days"; } else { displayTimeVal = "morethan30days"; } return displayTimeVal; }
I subtract the current time and pass milliseconds and convert in one day.
But the problem I ran into is that I could not calculate the exact time for the date in milliseconds.
I want to calculate for Today as: from Midnight 00:00 to Midnight 24:00. (Exactly within 24 hours.)
Similarly, I want to accurately convert milliseconds to Today, Yesterday, Last 7 days, Last 30 days and more than 30 days.
Jeevi source share