I'm trying to create a weather app in Android, using Open Weather map API. When I parse the JSON response from API, the time is shown in local time (IST) for sunrise and sunset, for all the cities.
I've finally found how to change time according to time zone. I have added the offset to the time stamp, in order to get the time at that particular time zone. However, while formatting the Linux timestamp I am getting "GMT+05:30" for all the cities, which shouldn't be the case.
long timeinMSSR = Long.parseLong(sunriseStr);
timeinMSSR = timeinMSSR - 19800 + timezone; // This app works in IST and India is 19800 seconds ahead of GMT. Hence Subtracting it from Linux timestamp. "timezone" is the variable that holds offset.
timeinMSSR = (timeinMSSR*1000);
Date dObjSR = new Date(timeinMSSR);
SimpleDateFormat timeFormatSR = new SimpleDateFormat("HH:MM a z");
String timeSunrise = timeFormatSR.format(dObjSR);
For the city of Coimbatore, the Linux timestamp is 1560904222, when I formatted I get: 06:06 am GMT+05:30. This is correct.
But for London, the Linux timestamp is 1560915765, when I formatted I get: 04:06 am GMT+05:30. However, the expected output is: 04:46 am GMT+01:00. Kindly help me to get the correct output.