0

in my case I have: "Sun, 11 Apr 21 09:09:13 +0000"

my code is:

    Long result = null;
    try {
        DateTimeFormatter dateFormatterRssPubDate = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z");
        result = dateFormatterRssPubDate.parseMillis(givenStringDate);
        if(result!=null && result>=0) 
           return result;
     } catch (Exception e) {
        // logging
     }

but it returns a negative number, such as: -61495771847000

Am I doing something wrong? if so, what is the best approach to convert a string date to millis with Joda in java?

alfa beta
  • 143
  • 1
  • 1
  • 6
  • Does this answer your question? [Joda Time & parsing two digit year correctly based on pivot](https://stackoverflow.com/questions/19143817/joda-time-parsing-two-digit-year-correctly-based-on-pivot) – Ole V.V. Apr 11 '21 at 12:46
  • As a side note, RSS uses RFC-822 date and time format, which allows two-digit years. RFC-1123 updates RFC-822 to use four-digit years. Further side note, java.time, the modern Java date and time API and the successor of Joda-Time, has a built-in formatter for RFC-1123, [DateTimeFormatter.RFC_1123_DATE_TIME](https://docs.oracle.com/javase/10/docs/api/java/time/format/DateTimeFormatter.html#RFC_1123_DATE_TIME). – Ole V.V. Apr 11 '21 at 13:00

1 Answers1

3

-61495771847000 is Sun Apr 11 0021 09:09:13, which is the value you gave.

If you want year 21 to be parsed as year 2021, then you should only specify a 2-digit year pattern, i.e. yy, not yyyy. If you do that, you get 1618132153000 as the result.

Andreas
  • 154,647
  • 11
  • 152
  • 247