Reputation: 131
I'm new to android and java, and I'm sure this is a rookie mistake but I did not realize it can be.
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, anio);
c.set(Calendar.MONTH, mes);
c.set(Calendar.DAY_OF_MONTH, dia);
c.set(Calendar.HOUR, hora);
c.set(Calendar.MINUTE, minuto);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Log.i("ET","anio: "+anio);
Log.i("ET","mes: "+mes);
Log.i("ET","year: "+c.YEAR);
Log.i("ET","month: "+c.MONTH);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((int) (c.getTimeInMillis() / 1000L));
Log.i("ET","Time c"+c.getTime());
Log.i("ET","Time calendar"+calendar.getTime());
return (int) (c.getTimeInMillis() / 1000L);
and the log
11-15 23:14:19.528: I/ET(13645): anio: 2013
11-15 23:14:19.528: I/ET(13645): mes: 10
11-15 23:14:19.528: I/ET(13645): year: 1
11-15 23:14:19.528: I/ET(13645): month: 2
11-15 23:14:19.528: I/ET(13645): Time cSat Nov 16 11:14:00 UYST 2013
11-15 23:14:19.528: I/ET(13645): Time calendarFri Jan 16 21:36:47 UYT 1970
Upvotes: 0
Views: 76
Reputation: 4126
When you reference values from a Calendar
object, you should use the get(int field)
method, where field
is a constant from the Calendar
class, such as Calendar.YEAR
. So, for example, instead of doing
Log.i("ET","year: "+c.YEAR);
you should do
Log.i("ET", "year: " + c.get(Calendar.YEAR));
I hope this helps; comment if you need further clarification.
Upvotes: 1