Motorola devices : org.threeten.bp.DateTimeException when parsing a date in ThreeTen

后端 未结 6 1812
猫巷女王i
猫巷女王i 2021-02-11 12:23

I have a very weird behaviour on some Motorola devices where LocalDateTime.now() is returning 0000-00-00T00:00:00.0 with ThreeTenABP.

The code

6条回答
  •  我寻月下人不归
    2021-02-11 12:46

    try this:-

    String dateFormat = "HH:mm:ss MM/dd/uuuu";
            String dateString = "11:30:59 02/31/2015";
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofPattern(dateFormat, Locale.US)
                .withResolverStyle(ResolverStyle.STRICT);
            try {
                LocalDateTime date = LocalDateTime.parse(dateString, dateTimeFormatter);
                System.out.println(date);
            } catch (DateTimeParseException e) {
                // Throw invalid date message
                System.out.println("Exception was thrown");
            }
    

提交回复
热议问题