java - SimpleDateFormat throws parse Exception for +0100 -


i trying 2 sets of date date format :

dateformat format = new simpledateformat("eee, dd mmm yyyy hh:mm:ss"); 

it works fine date : fri, 26 aug 2016 13:55:34 +0000

not date : tue, 06 sep 2016 11:57:14 +0100

throws exception +0100 date.

 unparseable date: "tue, 06 sep 2016 11:57:14 +0100" (at offset 0)  @ java.text.dateformat.parse(dateformat.java:555) 

it fails @ offset 0, means problem not related timezone day in letters.

you should set locale of simpledateformat.

    dateformat format = new simpledateformat("eee, dd mmm yyyy hh:mm:ss", locale.english);     date d1 = format.parse("fri, 26 aug 2016 13:55:34 +0000");     date d2 = format.parse("tue, 06 sep 2016 11:57:14 +0100"); 

works without problem.

if need retrieve timezone, have add z pattern:

    dateformat format = new simpledateformat("eee, dd mmm yyyy hh:mm:ss z", locale.english); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -