Skip to content

Latest commit

 

History

History
146 lines (134 loc) · 5.43 KB

README.md

File metadata and controls

146 lines (134 loc) · 5.43 KB

DateCraft

Maven Central Build Status Quality Gate Status Coverage Hits

Facade API to handling various date formats for Coordinated Universal Time also known as UTC.

DateCraft is a simple facade API to handling various date formats for Coordinated Universal Time also known as UTC.

Epoch millisecond examples

  • Getting current epoch millisecond
    DateCraft.currentEpochMilli();
  • Getting epoch millisecond from ISO-8601 format
    DateCraft.toEpochMilli("2021-01-01T12:34:56Z");
  • Getting epoch millisecond from specific date time with pattern
    DateCraft.toEpochMilli("2021-01-01 12:34:56", "uuuu-MM-dd HH:mm:ss");
  • Getting epoch millisecond from specific date time with pattern and time-zone
    DateCraft.toEpochMilli("2021-01-01 12:34:56", "uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));

Current date-time examples

  • Getting current date-time as a Coordinated Universal Time in ISO-8601 format
    DateCraft.currentDateTime();
  • Getting current date-time as a Coordinated Universal Time with specific pattern
    DateCraft.currentDateTime("uuuu-MM-dd HH:mm:ss");
  • Getting current date-time with specific time-zone in ISO-8601 format
    DateCraft.currentDateTime(ZoneId.of("GMT+9"));
  • Getting current date-time with specific pattern and time-zone
    DateCraft.currentDateTime("uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));

Time-zone examples

  • Getting UTC
    ZoneId timeZone = ZoneOffset.UTC;
  • Getting Asia/Seoul
    ZoneId timeZone = ZoneId.of("Asia/Seoul");
  • Getting GMT+9
    ZoneId timeZone = ZoneId.of("GMT+9");
  • Getting +9 offset hours (equals to GMT+9)
    ZoneId timeZone = ZoneOffset.ofHours(9);

Formatting examples

  • format(long epochMilli)
    // Returns "2021-01-01T12:34:56Z"
    DateCraft.format(1609504496000L);
  • format(long epochMilli, String pattern)
    // Returns "2021-01-01 12:34:56"
    DateCraft.format(1609504496000L, "uuuu-MM-dd HH:mm:ss");
  • format(long epochMilli, ZoneId timeZone)
    // Returns "2021-01-01T21:34:56+09:00"
    DateCraft.format(1609504496000L, ZoneId.of("GMT+9"));
  • format(long epochMilli, String pattern, ZoneId timeZone)
    // Returns "2021-01-01 21:34:56"
    DateCraft.format(1609504496000L, "uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));
  • format(String dateTime, String toPattern)
    // Returns "2021-01-01 12:34:56"
    DateCraft.format("2021-01-01T12:34:56Z", "uuuu-MM-dd HH:mm:ss");
  • format(String dateTime, ZoneId toTimeZone)
    // Returns "2021-01-01T21:34:56+09:00"
    DateCraft.format("2021-01-01T12:34:56Z", ZoneId.of("GMT+9"));
  • format(String dateTime, String fromPattern, String toPattern)
    // Returns "2021-01-01 12:34:56"
    DateCraft.format("01 Jan 2021, 12:34:56", "dd MMM uuuu, HH:mm:ss", "uuuu-MM-dd HH:mm:ss");
  • format(String dateTime, String toPattern, ZoneId toTimeZone)
    // Returns "2021-01-01 21:34:56"
    DateCraft.format("2021-01-01T12:34:56Z", "uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));
  • format(String dateTime, String fromPattern, ZoneId fromTimeZone, ZoneId toTimeZone)
    // Returns "2021-01-01 21:34:56"
    DateCraft.format("2021-01-01 12:34:56", "uuuu-MM-dd HH:mm:ss", ZoneOffset.UTC, ZoneId.of("GMT+9"));
  • format(String dateTime, String fromPattern, ZoneId fromTimeZone, String toPattern, ZoneId toTimeZone)
    // Returns "2021-01-01 21:34:56"
    DateCraft.format("01 Jan 2021, 12:34:56", "dd MMM uuuu, HH:mm:ss", ZoneOffset.UTC, "uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));

Parsing examples

  • parse(String dateTime, String fromPattern)
    // Returns "1970-01-01T00:00:00Z"
    DateCraft.parse("1970-01-01 00:00:00", "uuuu-MM-dd HH:mm:ss");
  • parse(String dateTime, String fromPattern, ZoneId fromTimeZone)
    // Returns "1970-01-01T00:00:00Z"
    DateCraft.parse("1970-01-01 09:00:00", "uuuu-MM-dd HH:mm:ss", ZoneId.of("GMT+9"));

Maven Central

<dependency>
    <groupId>org.silentsoft</groupId>
    <artifactId>datecraft</artifactId>
    <version>1.0.0</version>
</dependency>

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please note we have a CODE_OF_CONDUCT, please follow it in all your interactions with the project.

License

Please refer to LICENSE.