Skip to content

seleniumbrain/date-time-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Date Time Utility

GitHub Maven Central

Date Time Utility provides support to handle any date string in multiple ways.

Features

  • Validate date strings against supported formats
  • Determine the format of a given date string
  • Format date strings from one format to another
  • Convert date strings to LocalDateTime, LocalDate, LocalTime, and Date objects
  • Compare date and date-time strings
  • Calculate the difference between dates and times
  • Calculate the number of workdays between dates

Tools & Technologies

Tools/Technologies Name Version
JDK JDK 17+
Maven Maven 3.8.9
Lombok Lombok Latest
IntelliJ Idea Recommended IDE I - IntelliJ Community Edition
VS Code Recommended IDE II - VS Code Community Edition
Eclipse Recommended IDE III - Eclipse Community Edition

Installation

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>io.github.seleniumbrain</groupId>
    <artifactId>date-time-util</artifactId>
    <version>1.0.1</version>
</dependency>

Usage

Validate Date Strings

DateTimeUtils.FormatOptions options = DateTimeUtils.FormatOptions.builder()
        .locale(Locale.US)
        .zoneId(ZoneId.of("UTC")) // Use the desired time zone
        .zoneOffset(ZoneOffset.UTC) // Use the desired offset
        .build();
DateTimeUtils utils = new DateTimeUtils(options);
boolean isValid = utils.isValid("2024-12-20 14:30:00");
System.out.println(isValid); // Output: true

Determine Date Format

String format = utils.getFormatOf("2024-12-20 14:30:00");
System.out.println(format); // Output: yyyy-MM-dd HH:mm:ss

Format Date Strings

String formattedDate = utils.formatTo("12/20/2024 02:30:00 PM", DateTimeFormat.FORMAT_ISO_LOCAL_DATE);
System.out.println(formattedDate); // Output: 2024-12-20

Convert Date Strings

LocalDateTime dateTime = utils.toLocalDateTime("2024-12-20 14:30:00");
System.out.println(dateTime); // Output: 2024-12-20T14:30

Compare Dates

boolean isSameDate = utils.isDateEqualTo("2024-12-20", "2024-12-20T14:30:00+05:30");
System.out.println(isSameDate); // Output: true

Calculate Days Between Dates

long days = utils.calculateDaysBetween("2024-12-20", "2024-12-25");
System.out.println(days); // Output: 5

Calculate Workdays Between Dates

long workdays = utils.calculateWorkdaysBetween("2024-12-20", "2024-12-25");
System.out.println(workdays); // Output: 3

License

This project is licensed under the MIT License—see the LICENSE file for details.

Contact

For any questions or suggestions, please contact the project maintainers rajoviyaa.s@gmail.com


This README.md provides an overview of the date-time-util project, its features, installation instructions, and usage examples.

About

Handles date time string value

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages