So I am pulling data from the OpenWeatherMap api and everying was going fine until I got to returning the sunrise and sunset times for Omaha, Nebraska. Ive looked at previous posts on here and used those as reference such as one using the TimeUnit class which is still off in my case and ones using Date/SimlpeDateFormatter but it seems they are outputting nearly the same time. The method to convert these times may look right to me but the times they convert to are not so. Is there a certain method I should use to convert them or am i doing something wrong with the current method I am using?
Methods that intake the time in milliseconds
public String getSunrise() {
valueString = main.substring(main.indexOf("\"sunrise\"") + 10, main.indexOf("\"sunrise\"") + 20);
System.out.println(valueString);
Long rise = Long.parseLong(valueString);
Date d = new Date(rise);
SimpleDateFormat format = new SimpleDateFormat("h:mm a");
format.setTimeZone(TimeZone.getTimeZone("CDT"));
String t = format.format(d);
return t;
}
public String getSunset() {
valueString = main.substring(main.indexOf("\"sunset\"") + 9, main.indexOf("\"sunset\"") + 19);
System.out.println(valueString);
Long set = Long.parseLong(valueString);
Date d = new Date(set);
SimpleDateFormat format = new SimpleDateFormat("h:mm a");
format.setTimeZone(TimeZone.getTimeZone("CDT"));
String t = format.format(d);
return t;
}
Console output of the methods
1588504675
Sunrise: 9:15 AM
1588555387
Sunset: 9:15 AM
From the current data it is pulling, the time should be sunrise = 6:17am and sunset = 8:23pm taken from this link: https://openweathermap.org/city/5074472. main
is the full JSON string.
Methods that intake the time in milliseconds: The value in the Open Weather Map API is in seconds, not milliseconds. In your question, 1588504675
is in the year 1970. But 1588504675000
is May 3rd 2020 (and the time portion is UTC).