Simple Java library to convert common Date/Time objects. Use old style Date or Calendar and convert it to new Java 7+ Date/Time objects or visa versa.
Take a java.time.LocalDate
object, add time and zone and convert it to java.util.Date
with an one-liner.
Use DateConvert to convert Calendar, Instant, ZonedDateTime and even LocalDate.
For example:
// java.util.Date to Calendar with default zone
DateConvert.from(date).toCalendarWithDefaultZone();
// Calendar to java.time.ZonedDateTime
DateConvert.from(calendar).toZonedDateTime();
// java.time.LocalDate -> java.util.Date with time 12:30 and default zone
DateConvert.from(localDate).withLocalTime(12, 30, 0, 0).withDefaultZoneId().toDate();
- Calendar
- Date
- Instant
- LocalDate
- LocalDateTime
- Millis
- Timestamp
- ZonedDateTime
- Add JitPack repository to your build file, see here
- Add the DateConvert dependency
For maven the pom.xml looks like
...
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.github.javablick</groupId>
<artifactId>dateconvert</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
- Use the DateConvert class, e.g.
DateConvert.from(date).toCalendar();
Write me an email.
See also my homepage.