chrono-java icon indicating copy to clipboard operation
chrono-java copied to clipboard

Result Date Format

Open willpowr opened this issue 8 years ago • 2 comments

By default it appears that if a date 1/6/2017 is parsed, the output of result.date is Year=2017,Month=1,DayOfMonth=6. (US format 6th January 2017)

Is there a way to specify that the same input should be parsed to Year=2017,Month=6,DayOf Month=1 (UK format 1st June 2017)?

willpowr avatar Feb 19 '17 12:02 willpowr

Have exactly the same issue, cannot specify en_GB which appears on your JS library.

suseek avatar Mar 18 '19 21:03 suseek

@willpowr best would be to just implement your own ENSlashDateFormatParser and these two lines (42, 43) switch the groups, so at the end, it would look like this

        int day = Integer.parseInt(matcher.group(3));
        int month = Integer.parseInt(matcher.group(4));

then just

ChronoOption options = ChronoOption.standardOptions();
        options.parsers.add(new ENGBSlashDateFormatParser());
        new Chrono(options).parse("01/06/2017");

suseek avatar Mar 18 '19 22:03 suseek