August 14, 2022

Spring inject Date into bean property – CustomDateEditor

Spring example to show you how to inject a “Date” into bean property. In Spring, you can inject a Date via two methods. Factory bean: Declare a dateFormat bean, in “customer” bean, reference “dateFormat” bean as a factory bean. CustomDateEditor: The factory method will call SimpleDateFormat.parse() to convert String into Date object automatically.

Spring inject Date into bean property – CustomDateEditor Read More

How to compare dates in Java

This article shows few examples to compare two dates in Java. Updated with Java 8 examples. For the legacy java.util.Date, we can use compareTo, before(), after() and equals() to compare two dates. For the legacy java.util.Calendar, the Calendar works the same way as java.util.Date. And The Calendar contains the similar compareTo, before(), after() and equals() to compare two calender. For the new Java 8 java.time.* classes, all contains similar compareTo, isBefore(), isAfter() and isEqual() to compare two dates, and it works the same way.

How to compare dates in Java Read More

Java – Convert date and time between timezone

In this tutorial, we will show you few examples (ZonedDateTime (Java 8), Date, Calendar and Joda Time) to convert a date and time between different time zones. For time zone, avoid both Date and Calendar: If you are using JDK >= 8, use the new java.time.* framework; If you are using JDK < 8, use Joda Time. (The new Java 8 java.time.* framework is inspired by this library)

Java – Convert date and time between timezone Read More