I want to parse a date with timezone from a string in the format "31-12-2014 18:09 +05:30"
. I tried to parse using simple-Date-Format using "d-MM-yyyy HH:mm ZZ"
and "d-MM-yyyy HH:mm Z"
. But it is giving me a un-parables date exception. How to do this?
Please help me.
DateFormat getTimeZone() Method in Java with ExamplesThe getTimeZone() method in DateFormat class is used to return the current time-zone of the calendar of this DateFormat. Parameters: The method does not take any parameters. Return Value: The method returns timezone associated with the calendar of DateFormat.
You can display timezone easily in Java using SimpleDateFormat(“z”).
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm XXX");
Date d = sdf.parse("31-12-2014 18:09 +05:30");
System.out.println(d);
Note that you can't use X
before SimpleDateFormat of JDK7, because it's the ISO 8601 time zone format.
With Java 6 you can only use ZZZ
but it won't match +05:30 because Z
match RFC 822 time zone format
If you're using Java 6, please refer to this answer : Converting ISO 8601-compliant String to java.util.Date
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