Hora incorrecta de devolución del calendario
Frecuentes
Visto 639 veces
0
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?
1 Respuestas
3
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