Skip to content

Library to convert any Java Dates (Timestamp, LocalDateTime, ...)

License

Notifications You must be signed in to change notification settings

javablick/DateConvert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.