The application implements
Joda Time API to convert date and time from one time zone to another. Since I use Dubuque, Kathmandu and London times routinely, I also saw the need to create a separate Activity.
Current Time Code:
For London for example,
1
| london.setText("\nLondon:\n" + joda("Europe/London"));
|
1
2
3
4
5
6
7
8
9
| /**
* @param destTime: Time Zone identifier as defined by Joda API
* @return Joda time String in selected format
*/
public String joda(String destTime) {
DateTime current = new DateTime();
current = current.withZone(DateTimeZone.forID(destTime));
return (DateTimeFormat.forPattern("HH:mm:ss\ndd MMM yyyy ZZ").print(current));
}
|
Time Conversion Code:
1
2
3
4
| DateTimeZone zone = DateTimeZone.forID(sourceTime);
DateTime dt = new DateTime(year, month, day, hour, minute, 0, zone);
dt = dt.withZone(DateTimeZone.forID(destTime));
result.setText(DateTimeFormat.forPattern("HH:mm:ss\ndd/MM/yyyy\nZZ").print(dt));
|