Reputation: 121
I have managed to get a specific timezone using the TimeZone utility, for now I am using the .getDefault as an example. However I cannot get the exact time in the country with just this, so I was wondering how would I implement it? And would I have to use the calendar? Below is my code.
TimeZone tz = TimeZone.getDefault();
String TimeZoneName = tz.getDisplayName();
int TimeZoneOffset = tz.getRawOffset()/(60 * 60 * 1000);
t.setText("default time zone:" +
TimeZoneName + " : " +String.valueOf(TimeZoneOffset) + tz.getID() );
this comes with default timezone: Greenwich Meantime, gmt:0, Europe/Dublin, and I would like it to display the exact time on the end. Thanks for your help!
Upvotes: 2
Views: 502
Reputation: 2928
Joda Time has a complete list ofCanonical ID
from where you can get TimeZone depending on the Canonical ID
.
So, if you want to get the local time in New York at this very moment, you would do the following
// get current moment in default time zone
DateTime dt = new DateTime();
// translate to New York local time
DateTime dtNewYork = dt.withZone(DateTimeZone.forID("America/New_York"));
Upvotes: 2