Calendar HOUR_OF_DAY and MINUTE

3

I have this problem:

    Calendar c = Calendar.getInstance();
    Log.i("RESULTADO", String.valueOf(c.get(Calendar.HOUR_OF_DAY)));
    Log.i("RESULTADO", String.valueOf(c.get(Calendar.MINUTE)));

This gives in the logcat:

I/RESULTADO: 10
I/RESULTADO: 40

And it's 19:25. The same code with an IDE that is not Android Studio gives the correct result. Do you know why it fails?

    
asked by Red 18.06.2016 в 19:26
source

1 answer

0

if they are 19:25 it should result in 19 and 25 for being a value of 24 hours.

If in another IDE you get the correct value, it seems to me that the problem is the time zone that is being taken by default. I suggest you define the time zone.

Calendar c = Calendar.getInstance(TimeZone
                .getTimeZone("America/Los_Angeles"));
Log.i("RESULTADO", String.valueOf(c.get(Calendar.HOUR_OF_DAY)));
Log.i("RESULTADO", String.valueOf(c.get(Calendar.MINUTE)));
    
answered by 18.06.2016 / 19:37
source