java.time.format.DateTimeParseException: Text could not be parsed at index 3

First of all, check the javadoc. The uppercase D represents the day-of-year field (not the day-of-month as you want), and uppercase Y represents the week-based-year field (not the year as you want). The correct patterns are the lowercase letters d and y. Also, you’re using month names in uppercase letters (JAN and FEB), so your … Read more

Is Joda Time deprecated with java 8 Date and Time API? (java.time)

The official statement of the author of Joda-time himself is to migrate as soon as Java-8 is available. See also this citation from the website: Note that Joda-Time is considered to be a largely “finished” project. No major enhancements are planned. If using Java SE 8, please migrate to java.time (JSR-310). So the short answer … Read more

Why Instant does not support operations with ChronoUnit.YEARS?

I’m taking a stab at it in what looks to me like something very logical. Here is the code for the method plus(long, TemporalUnit) (which is used in minus(…)): @Override public Instant plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plus(amountToAdd / … Read more

Why does String.replaceAll() work differently in Java 8 from Java 9?

Most likely due to JDK-6609854 and JDK-8189343 which reported negative nested character classes handling (in your example [^[0-9-]]). This behavior was fixed in 9 and 10, but fix was not backported to 8. The bug for Java 8 is explained as: In Java, the negation does not apply to anything appearing in nested [brackets] So … Read more

How to create an infinite stream with Java 8

Yes, there is an easy way: IntStream.iterate(0, i -> i + 2); With as usecase: IntStream.iterate(0, i -> i + 2) .limit(100) .forEach(System.out::println); Which prints out 0 to 198 increasing in steps of 2. The generic method is: Stream.iterate(T seed, UnaryOperator<T> f); The latter may be more uncommon in usage.

Is there a class in java.time comparable to the Joda-Time Interval?

Sorry for you, there is no equivalent in JSR-310 to JodaTime-Interval-class. I have doubts if this will ever come, but project lead Stephen Colebourne considers at least to support it in the scope of his external library Threeten-Extra, see this issue. If you are happy with JodaTime you should keep it. Not everything in JodaTime … Read more

How to convert from Instant to LocalDate

Java 9+ LocalDate.ofInstant(…) arrived in Java 9. Instant instant = Instant.parse(“2020-01-23T00:00:00Z”); ZoneId zone = ZoneId.of(“America/Edmonton”); LocalDate date = LocalDate.ofInstant(instant, zone); See code run live at IdeOne.com. Notice the date is 22nd rather than 23rd as that time zone uses an offset several hours before UTC. 2020-01-22 Java 8 If you are using Java 8, then … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)