Hora incorrecta de devolución del calendario

I use a calendar for the alarm in my app, but if I use the calendar, the timeInMillis are wrong.
Te muestro un ejemplo:

// Get Current Time
Calendar calNow = Calendar.getInstance();
calNow.setTimeInMillis(System.currentTimeMillis());
calNow.add(Calendar.HOUR, calNow.get(Calendar.HOUR_OF_DAY));
calNow.add(Calendar.MINUTE, calNow.get(Calendar.MINUTE));
long now = calNow.getTimeInMillis();

Corto now returns for example: 1345848049917
now debe ser el mismo que System.currentTimeMillis(), but it isn't, system devoluciones 1345846849921

now is in my timezone: 25.08.2012 - 00:40:49
System.currentTimeMillis() es: 25.08.2012 - 00:20:49

Exactly 20 Minutes later, but why?

preguntado el 24 de agosto de 12 a las 23:08

1 Respuestas

I'm not quite sure what you were trying to do, but these rows

calNow.add(Calendar.HOUR, calNow.get(Calendar.HOUR_OF_DAY));
calNow.add(Calendar.MINUTE, calNow.get(Calendar.MINUTE));

doubles the hours and minutes of the day, turning 00:20:49 dentro 00:40:49.

Respondido 24 ago 12, 23:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.