smart-date-generator
https://search.maven.org/artifact/jp.spring-boot-reference/smart-date-generator/1.0/jar https://oss.sonatype.org/content/repositories/releases/jp/spring-boot-reference/smart-date-generator/
SmartDateGenerator
SmartDateGenerator convert Date/Calendar/String
object to another object simply ( by one-liner ).
This library also help you to do date-caliculation with simple method-chain .
Usage
Generate Data from Date
or Calender
Object.
/* 2019/01/20 */
// generate CalenderObject from dateObject.
SmartDateGenerator.generateDate(new Date()).toCalender() // -> Calender Object.
// generate DateObject from CalenderObject.
SmartDateGenerator.generateDate(Calender.getInstance()).toDate() // -> Date Object.
// generate String from Object and given format.
SmartDateGenerator.generateDate(new Date()).toString("yyyy/MM/dd") -> "2019/01/20"
GenerateData from DateString
and format
You can get date-Data easily from dateString and it's format.
SmartDateGenerator.generateDate("2017/05/04 11:22", "yyyy/MM/dd").toDate()
// -> Thu May 04 00:00:00 JST 2017
SmartDateGenerator.generateDate("2017/05/04 11:22", "yyyy/MM/dd").toCalender()
// -> CalenderObject (2017/05/04)
Date-caliculation
you can caliculate date with method-chain
// 90 days after .
SmartDateGenerator.generateDate(new Date()).dayChange(90).toString("yyyy/MM/dd") // -> 2019/04/20
// 90 days before.
SmartDateGenerator.generateDate(new Date()).dayChange(-90).toString("yyyy/MM/dd") // -> 2018/10/22
calicate result can also be Date
,Calender
of cource.
// 90 days after .
SmartDateGenerator.generateDate(new Date()).dayChange(90).toDate() // -> DateObject()
// 90 days before.
SmartDateGenerator.generateDate(new Date()).dayChange(-90).toCalender() // -> CalenderObject
Set timezone
SmartDateGenerator.generateDate(testDate()).dayChange(-30).setTimeZone(TimeZone.getTimeZone("US/Alaska")).toString("yyyy/MM/dd")
// -> 2018/12/21
simple usage.
// this return DateObject (time is now).
SmartDateGenerator.generateDate().toDate() // -> Date (date:Sun Jan 20 22:33:22 JST 2019 )
Dependency
Maven
<dependency>
<groupId>jp.spring-boot-reference</groupId>
<artifactId>smart-date-generator</artifactId>
<version>1.0</version>
</dependency>
Gradle
compile 'jp.spring-boot-reference:smart-date-generator:1.0'