user2323036
user2323036

Reputation: 1585

How to get GMT/IST details from timezone object?

How to get the zone info from timezone object?

I have a TimeZone java object and I need to display the info as below

ex: IST - India Standard Time - (GMT+5.30)

I can get the IST - id and display name (Indian Standard Time) and offset as 5:30.

How to get the zone - GMT ???

Thanks.

Upvotes: 0

Views: 1135

Answers (2)

NamingException
NamingException

Reputation: 2404

For displaying in zone-Id - zone-Name - (GMT standard offset) format

  1. set to required time zone

  2. get required data from above object

TimeZone tz = TimeZone.getTimeZone("Asia/Calcutta");

tz.getID()              // for zone-id
tz.getDisplayName()         // for zone-Name
tz.getOffset(TimeZone.getDefault().getID()) // for GMT standard offset

Upvotes: 2

Laksitha Ranasingha
Laksitha Ranasingha

Reputation: 4517

Simply use TimeZone.getTimeZone("GMT"). If you want to check if ID exists try using TimeZone.getAvailableIDs().

Upvotes: 0

Related Questions