To Offset for time differences
You should use a format to send the data that includes the timezone within it.
You could:
- Use UNIX time which does not use timezones (milliseconds since epoch) with GMT 00, and also use this on java side
see:
Get current date/time in seconds
- Use ISO-8601 which is a standard and can include the timezone as well of the browser, and then parse this server side:
see:
To Calculate the Difference (using MS and Calendar Object)
You need to use the calendar object.
You create a calendar object and set with a future date: e.g. How to set Java.util.calendar to a specific time period in the future
Then you can perform a calculation by subtracting the current date (as long) with the long returned by the calendar, and dividing by (1000*60*60*24).
Some code I used in my own application to find entries greater than a specific datetime (midnight):
long currentTimeStamp = System.currentTimeMillis();
Calendar cal;
cal = Calendar.getInstance();
cal.setTime(new Date(currentTimeStamp));
//GET MS OF MIDNIGHT FROM BEGINNING OF THE DAY
cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND,0);
long midnight = cal.getTimeInMillis();
if(currentTimeStamp - midnight > (30*24*60*60*1000))break;