Git Product home page Git Product logo

datecraft's Introduction

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.

datecraft's People

Contributors

silentsoft avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.