Skip to content

Instantly share code, notes, and snippets.

@makuk66
Created May 17, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makuk66/8e145819e265ac2b8aff4a5b2b598768 to your computer and use it in GitHub Desktop.
Save makuk66/8e145819e265ac2b8aff4a5b2b598768 to your computer and use it in GitHub Desktop.
Different handling of `hh`:
groovy:000> import java.text.SimpleDateFormat
===> java.text.SimpleDateFormat
groovy:000> parser=new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy Z")
===> java.text.SimpleDateFormat@fee3c270
groovy:000> parser.parse("Wed Sep 30 17:14:25 2015 -0700")
===> Thu Oct 01 01:14:25 BST 2015
groovy:000> parser2=new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z")
===> java.text.SimpleDateFormat@87bd4670
groovy:000> parser2.parse("Wed Sep 30 17:14:25 2015 -0700")
===> Thu Oct 01 01:14:25 BST 2015
groovy:000> import org.joda.time.format.DateTimeParser
===> org.joda.time.format.DateTimeParser
groovy:000> import org.joda.time.format.DateTimeFormat
===> org.joda.time.format.DateTimeParser, org.joda.time.format.DateTimeFormat
groovy:000> jparser=org.joda.time.format.DateTimeFormat.forPattern("EEE MMM d hh:mm:ss yyyy Z")
===> org.joda.time.format.DateTimeFormatter@651905c5
groovy:000> jparser.parseDateTime("Wed Sep 30 17:14:25 2015 -0700")
ERROR org.joda.time.IllegalFieldValueException:
Cannot parse "Wed Sep 30 17:14:25 2015 -0700": Value 17 for clockhourOfHalfday must be in the range [1,12]
at org.joda.time.field.FieldUtils.verifyValueBounds (FieldUtils.java:234)
at org.joda.time.field.ZeroIsMaxDateTimeField.set (ZeroIsMaxDateTimeField.java:86)
at org.joda.time.format.DateTimeParserBucket$SavedField.set (DateTimeParserBucket.java:568)
at org.joda.time.format.DateTimeParserBucket.computeMillis (DateTimeParserBucket.java:447)
at org.joda.time.format.DateTimeParserBucket.computeMillis (DateTimeParserBucket.java:411)
at org.joda.time.format.DateTimeFormatter.parseDateTime (DateTimeFormatter.java:882)
at org.joda.time.format.DateTimeFormatter$parseDateTime.call (Unknown Source)
groovy:000> jparser2=org.joda.time.format.DateTimeFormat.forPattern("EEE MMM d HH:mm:ss yyyy Z")
===> org.joda.time.format.DateTimeFormatter@49c99fc
groovy:000> jparser2.parseDateTime("Wed Sep 30 17:14:25 2015 -0700")
===> 2015-10-01T01:14:25.000+01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment