I am trying to get an abbreviated time zone, ex. PST, EDT etc. I managed to get an offset but was unable to get an abbreviated timezone based on the offset.
Can anyone help?
For example, when
tz = America/Phoenix and time =1450759239340
DateTimeFormat.forPattern("zzz").withZone(tz).print(time);
I get -07:00 as a result.
Can I get an abbreviated time zone with these available code?
Thanks in advance.
Here is how , you can get different date format using SimpleDateFormat and Calendar class.
One of these is to get PDT, IST kind of output using z in small case.
if you want elaborated names use zzzz.
I would recommend choosing you desired date format from below:
"yyyy.MM.dd G 'at' HH:mm:ss z" 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy" Wed, Jul 4, '01
"h:mm a" 12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" 02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 2001-07-04T12:08:56.235-0700
You may use SimpleDateFormat to get proper formatted string from date or vice-versa.
For example
String originalString = "2010-07-14 09:00:02";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(originalString);
String newString = new SimpleDateFormat("H:mm").format(date);
See my blog on same.
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With