Date Time Utility provides support to handle any date string in multiple ways.
- 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, andDateobjects - Compare date and date-time strings
- Calculate the difference between dates and times
- Calculate the number of workdays between dates
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>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: trueString format = utils.getFormatOf("2024-12-20 14:30:00");
System.out.println(format); // Output: yyyy-MM-dd HH:mm:ssString formattedDate = utils.formatTo("12/20/2024 02:30:00 PM", DateTimeFormat.FORMAT_ISO_LOCAL_DATE);
System.out.println(formattedDate); // Output: 2024-12-20LocalDateTime dateTime = utils.toLocalDateTime("2024-12-20 14:30:00");
System.out.println(dateTime); // Output: 2024-12-20T14:30boolean isSameDate = utils.isDateEqualTo("2024-12-20", "2024-12-20T14:30:00+05:30");
System.out.println(isSameDate); // Output: truelong days = utils.calculateDaysBetween("2024-12-20", "2024-12-25");
System.out.println(days); // Output: 5long workdays = utils.calculateWorkdaysBetween("2024-12-20", "2024-12-25");
System.out.println(workdays); // Output: 3This project is licensed under the MIT License—see the LICENSE file for details.
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.