Obsolete format
Your example data is odd. As I recall the old email standards use RFC 1123 or RFC 822. Your format is similar, but missing the colon between hour and minute of the offset, and has extraneous parens around the pseudo-zone.
Be aware that such formats are obsolete. They are difficult to parse by machine. And they assume English language and particular cultural norms. Modern protocols adopted ISO 8601 formats instead. The ISO 8601 formats are used by default in the java.time classes.
java.time
If you really must parse text in that specific format, define a DateTimeFormatter
to match its formatting pattern.
String input = "Tue, 21 Apr 2015 07:12:18 -0700 (PDT)";
DateTimeFormatter f = DateTimeFormatter.ofPattern( "EEE, dd MMM uuuu HH:mm:ss XXXX '('z')'" ).withLocale( Locale.US );
Parse as a ZonedDateTime
.
ZonedDateTime zdt = ZonedDateTime.parse( input , f );
zdt.toString(): 2015-04-21T07:12:18-07:00[America/Los_Angeles]
Note that PDT
is not a real time zone names. Never use these 2-4 letter pseudo-zones. Real time zones have a name in Continent/Region
format such as America/Los_Angeles
.