En primer lugar, sé que puedo usar
Calendar, but I want to understand this problem and learn to solve it.
Date with the current date. I want to set hours, minutes and seconds to 0. I do it with this code:
current_date.setHours(0); current_date.setMinutes(0); current_date.setSeconds(0);
Something is going wrong because if I do that, the day gets decreased by 1, for example, if today is 31, the day gets set to 30.
why? How can it be solved with
Date (sin uso
Calendar, I want to learn how to solve this problem by the hard way). Thanks
preguntado el 31 de julio de 12 a las 13:07
I guess it has to do with time-zone.
When you set HMS to 0 you are not setting them according to your time zone, but according to UTC (not 100% sure, but...). So the resulting date is not:
0:0:0 YOUR LOCAL
and that's a day before if you are on America.
Try to set minutes to
-yourDate.getTimezoneOffset() (try with positive value if it doesn't work).