Calendar and getTimeInMillis(). Android.

2019-09-06 18:03发布

问题:

I have next code:

Calendar cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, mYear); /2011
        cal.add(Calendar.MONTH, mMonth); /04
        cal.add(Calendar.DAY_OF_MONTH, mDay);/13 
        cal.add(Calendar.HOUR, mHour); /11
        cal.add(Calendar.MINUTE, mMinute); /53 
    System.out.println("Cal time "+ cal.getTimeInMillis());
    System.out.println("System time " +System.currentTimeMillis());

cal time 64775494376227 System time 1302724616231 What's wrong in my code?

回答1:

The problem is Calendar.getInstance() is already initialized to the current date/time. You're returning the millis time for for sometime in 4022...not 2011. See the JavaDoc for more info.