Answer the question
In order to leave comments, you need to log in
How does the Calendar class work in this code?
Hello.
Tell me how the Calendar class works in this code
public static Calendar getDate() {
Calendar date = Calendar.getInstance();
date.setTimeInMillis(timestamp * 1000);
return date;
}
timstamp - time received from open weather map. By request I receive weather data for 5 days and write it to List. Judging by the response from the server, I get a list of elements for 5 days with an interval of 3 hours. I 'm trying to display the weather data on the screen in a loop with the condition
if (weatherDay.getDate().get(Calendar.HOUR_OF_DAY) == 15), in the response timstamp = 1615215600 at the time of 15:00, but I get a shift of 2 hours ahead, and the number of the month by 1 ago, and naturally I do not fall into this condition. How to be in this situation?
Answer the question
In order to leave comments, you need to log in
Good afternoon!
In the last question, you said that you solved the issue.
How to solve the problem with "Unable to create converter for class"?
On the virtual device, the time zone was set to GTM-0 in the settings, and I have +2. This solved the problem.
public static Calendar getDate() {
Calendar date = Calendar.getInstance();
date.setTimeInMillis(timestamp * 1000);
return date;
}
public static void main(String[] args) {
long timestamp = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
// Ваш код:
calendar.setTimeInMillis(timestamp * 1000);
System.out.println(calendar.getTime());
// Мой код:
calendar.setTimeInMillis(timestamp);
System.out.println(calendar.getTime());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question