Count days between two date - J2ME

2019-06-26 03:32发布

问题:

I want to count days between two date, I found some solutions on the net but the problem is in my NetBeans the GregorianCalendar is not available. So cant calculate the days. Can anyone help ?

回答1:

In Java Micro Edition you don't have GregorianCalendar, so you have to use:

Date startDate, endDate;
...
int days = (int) ((endDate.getTime() - startDate.getTime())  
    / (1000 * 60 * 60 * 24)); 

Where the getTime() method of a Date returns the number of milliseconds since January 1, 1970, 00:00:00 GMT



标签: java java-me