Library to convert any Java Dates (Timestamp, LocalDateTime, ...)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
.settings
src
.coveralls.yml
.gitignore
.project
.travis.yml
LICENSE
Readme.md
pom.xml

Readme.md

Build Status CircleCI Coverage Status

DateConvert

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.

Usage

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();

Converts from/to

  • Calendar
  • Date
  • Instant
  • LocalDate
  • LocalDateTime
  • Millis
  • Timestamp
  • ZonedDateTime

Quickstart

  1. Add JitPack repository to your build file, see here
  2. 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>
  1. Use the DateConvert class, e.g. DateConvert.from(date).toCalendar();

Questions? Need help?

Write me an email.

See also my homepage.