0

I read many of similar SO questions regarding this very topic, but I still am confused how to do it now... I try to make it simpel:

I got this String: "Sat Jan 24 00:00:00 GMT+100 2015" which shall not be modified in any way

My question now is: What kind of pattern shall I use to parse this String into a java.util.Date? I tried: "EEE MMM dd HH:mm:ss z yyyy" but it fails with "unparsable Date"

What I know is: If I'd have "Sat Jan 24 00:00:00 GMT+1:00 2015", which is the same (right?), then my pattern works. But I can't (want..) modify it.

--> Is there a pattern which works out of the box, yes or no?

PS: I assume this question ends as duplicate of one of all the others, but if you vote so, please answer my bold question in addition, as I could not read it out of there with certainty

regards and thanks in advance

BAERUS
  • 4,009
  • 3
  • 24
  • 39
  • possible duplicate of [Parse a String to Date in Java](http://stackoverflow.com/questions/11446420/parse-a-string-to-date-in-java) – Mudassar Jul 07 '15 at 09:06

2 Answers2

2

"Hours must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively."

as per java time zone specification http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html and this is what i found for three letter time zone Three-letter time zone IDs

For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

so i do not think there is any out of box pattern which works for you. check the other answer .

Santanu Sahoo
  • 1,137
  • 11
  • 29
  • Alright, so the answer is definitely "NO, there is no matching pattern". I ask myself, why GWT is producing such a damn string then, but nevermind. So I go for manipulating then. Thanks to all others answering! – BAERUS Jul 07 '15 at 09:37
0

I don't think there is a pattern that can match your timezone / offset GMT+100. You could amend the input before parsing:

String input = "Sat Jan 24 00:00:00 GMT+100 2015";
input = input.replaceAll("([+-])(\\d+?)(\\d{2})", "$1$2:$3");

String pattern = "EEE MMM dd HH:mm:ss z yyyy";
Date date = new SimpleDateFormat(pattern, Locale.ENGLISH).parse(input);
assylias
  • 321,522
  • 82
  • 660
  • 783