Class DateTimeUtils

java.lang.Object
de.edgesoft.edgeutils.datetime.DateTimeUtils

public class DateTimeUtils
extends java.lang.Object
Utility methods for date, time, and datetime.

Legal stuff

Copyright 2010-2020 Ekkart Kleinod ekleinod@edgesoft.de

This file is part of edgeutils.

edgeutils is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

edgeutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with edgeutils. If not, see http://www.gnu.org/licenses/.

Since:
0.9.0
Version:
0.13.0
Author:
Ekkart Kleinod
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String DATE_PATTERN
    Standard pattern for dates.
    static java.lang.String DATETIME_PATTERN
    Standard pattern for datetimes.
    static java.lang.String TIME_PATTERN
    Standard pattern for times.
  • Constructor Summary

    Constructors 
    Constructor Description
    DateTimeUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String formatDate​(java.time.LocalDate theDate)
    Format LocalDate with standard pattern/formatter.
    static java.lang.String formatDate​(java.time.LocalDate theDate, java.lang.String thePattern)
    Format LocalDate with given pattern.
    static java.lang.String formatDate​(java.time.LocalDate theDate, java.time.format.DateTimeFormatter theFormatter)
    Format LocalDate with given formatter.
    static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime)
    Format LocalDateTime with standard pattern/formatter.
    static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime, java.lang.String thePattern)
    Format LocalDateTime with given pattern.
    static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime, java.time.format.DateTimeFormatter theFormatter)
    Format LocalDateTime with given formatter.
    static java.lang.String formatDateTimeAsDate​(java.time.LocalDateTime theDateTime)
    Format datetime as date.
    static java.lang.String formatDateTimeAsTime​(java.time.LocalDateTime theDateTime)
    Format datetime as time.
    static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor)
    Format TemporalAccessor with standard pattern/formatter.
    static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor, java.lang.String thePattern)
    Format TemporalAccessor with given pattern.
    static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor, java.time.format.DateTimeFormatter theFormatter)
    Format TemporalAccessor with given DateTimeFormatter.
    static java.lang.String formatTime​(java.time.LocalTime theTime)
    Format LocalTime with standard pattern/formatter.
    static java.lang.String formatTime​(java.time.LocalTime theTime, java.lang.String thePattern)
    Format LocalTime with given pattern.
    static java.lang.String formatTime​(java.time.LocalTime theTime, java.time.format.DateTimeFormatter theFormatter)
    Format LocalTime with given formatter.
    static javafx.util.StringConverter<java.time.LocalDate> getDateConverter()
    Returns date converter e.g.
    static javafx.util.StringConverter<java.time.LocalDate> getDateConverter​(java.lang.String thePattern)
    Returns date converter e.g.
    static javafx.util.StringConverter<java.time.LocalDate> getDateConverter​(java.time.format.DateTimeFormatter theFormatter)
    Returns date converter e.g.
    static boolean isValidDate​(java.lang.String theString)
    Is string valid date?
    static boolean isValidDate​(java.lang.String theString, java.lang.String thePattern)
    Is string valid date?
    static boolean isValidDate​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
    Is string valid date?
    static boolean isValidTime​(java.lang.String theString)
    Is string valid time?
    static boolean isValidTime​(java.lang.String theString, java.lang.String thePattern)
    Is string valid time?
    static boolean isValidTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
    Is string valid time?
    static java.time.LocalDate parseDate​(java.lang.String theString)
    Parse date with standard pattern/formatter.
    static java.time.LocalDate parseDate​(java.lang.String theString, java.lang.String thePattern)
    Parse date with given pattern.
    static java.time.LocalDate parseDate​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
    Parse date with given formatter.
    static java.time.LocalDateTime parseDateTime​(java.lang.String theString)
    Convert text to LocalDateTime.
    static java.time.LocalDateTime parseDateTime​(java.lang.String theString, java.lang.String thePattern)
    Convert text to LocalDateTime trying pattern and then standard patterns.
    static java.time.LocalDateTime parseDateTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
    Convert text to LocalDateTime trying formatter and then standard formatters.
    static java.time.LocalTime parseTime​(java.lang.String theString)
    Parse time with standard pattern/formatter.
    static java.time.LocalTime parseTime​(java.lang.String theString, java.lang.String thePattern)
    Parse time with given pattern.
    static java.time.LocalTime parseTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
    Parse time with given formatter.
    static java.util.Date toDate​(java.time.LocalDate theDate)
    Convert LocalDate to Date.
    static java.util.Date toDate​(java.time.LocalDateTime theDateTime)
    Convert LocalDateTime to Date.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • formatTemporalAccessor

      public static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor)
      Format TemporalAccessor with standard pattern/formatter.
      Parameters:
      theAccessor - accessor
      Returns:
      formatted accessor
      Since:
      0.12.0
    • formatTemporalAccessor

      public static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor, java.lang.String thePattern)
      Format TemporalAccessor with given pattern.
      Parameters:
      theAccessor - accessor
      thePattern - pattern (null = standard pattern)
      Returns:
      formatted accessor
      Since:
      0.9.7
    • formatTemporalAccessor

      public static java.lang.String formatTemporalAccessor​(java.time.temporal.TemporalAccessor theAccessor, java.time.format.DateTimeFormatter theFormatter)
      Format TemporalAccessor with given DateTimeFormatter.
      Parameters:
      theAccessor - accessor
      theFormatter - formatter (null = standard formatter)
      Returns:
      formatted accessor
      Since:
      0.12.0
    • formatDate

      public static java.lang.String formatDate​(java.time.LocalDate theDate)
      Format LocalDate with standard pattern/formatter.
      Parameters:
      theDate - date
      Returns:
      formatted date
      Since:
      0.9.2
    • formatDate

      public static java.lang.String formatDate​(java.time.LocalDate theDate, java.lang.String thePattern)
      Format LocalDate with given pattern.
      Parameters:
      theDate - date
      thePattern - pattern (null = standard pattern)
      Returns:
      formatted date
      Since:
      0.9.7
    • formatDate

      public static java.lang.String formatDate​(java.time.LocalDate theDate, java.time.format.DateTimeFormatter theFormatter)
      Format LocalDate with given formatter.
      Parameters:
      theDate - date
      theFormatter - formatter (null = standard formatter)
      Returns:
      formatted date
      Since:
      0.12.0
    • formatDateTime

      public static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime)
      Format LocalDateTime with standard pattern/formatter.
      Parameters:
      theDateTime - datetime
      Returns:
      formatted datetime
      Since:
      0.9.7
    • formatDateTime

      public static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime, java.lang.String thePattern)
      Format LocalDateTime with given pattern.
      Parameters:
      theDateTime - datetime
      thePattern - pattern (null = standard pattern)
      Returns:
      formatted datetime
      Since:
      0.9.7
    • formatDateTime

      public static java.lang.String formatDateTime​(java.time.LocalDateTime theDateTime, java.time.format.DateTimeFormatter theFormatter)
      Format LocalDateTime with given formatter.
      Parameters:
      theDateTime - datetime
      theFormatter - formatter (null = standard formatter)
      Returns:
      formatted datetime
      Since:
      0.12.0
    • formatTime

      public static java.lang.String formatTime​(java.time.LocalTime theTime)
      Format LocalTime with standard pattern/formatter.
      Parameters:
      theTime - time
      Returns:
      formatted time
      Since:
      0.9.7
    • formatTime

      public static java.lang.String formatTime​(java.time.LocalTime theTime, java.lang.String thePattern)
      Format LocalTime with given pattern.
      Parameters:
      theTime - time
      thePattern - pattern (null = standard pattern)
      Returns:
      formatted time
      Since:
      0.9.7
    • formatTime

      public static java.lang.String formatTime​(java.time.LocalTime theTime, java.time.format.DateTimeFormatter theFormatter)
      Format LocalTime with given formatter.
      Parameters:
      theTime - time
      theFormatter - formatter (null = standard formatter)
      Returns:
      formatted time
      Since:
      0.12.0
    • formatDateTimeAsDate

      public static java.lang.String formatDateTimeAsDate​(java.time.LocalDateTime theDateTime)
      Format datetime as date.
      Parameters:
      theDateTime - datetime
      Returns:
      formatted datetime as date
      Since:
      0.9.7
    • formatDateTimeAsTime

      public static java.lang.String formatDateTimeAsTime​(java.time.LocalDateTime theDateTime)
      Format datetime as time.
      Parameters:
      theDateTime - datetime
      Returns:
      formatted datetime as time
      Since:
      0.9.7
    • parseDate

      public static java.time.LocalDate parseDate​(java.lang.String theString)
      Parse date with standard pattern/formatter.
      Parameters:
      theString - date string
      Returns:
      date
      Since:
      0.9.2
    • parseDate

      public static java.time.LocalDate parseDate​(java.lang.String theString, java.lang.String thePattern)
      Parse date with given pattern.
      Parameters:
      theString - date string
      thePattern - pattern (null = standard pattern)
      Returns:
      date
      Since:
      0.9.7
    • parseDate

      public static java.time.LocalDate parseDate​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
      Parse date with given formatter.
      Parameters:
      theString - date string
      theFormatter - formatter (null = standard formatter)
      Returns:
      date
      Since:
      0.12.0
    • isValidDate

      public static boolean isValidDate​(java.lang.String theString)
      Is string valid date?
      Parameters:
      theString - date string
      Returns:
      valid date?
      Since:
      0.9.2
    • isValidDate

      public static boolean isValidDate​(java.lang.String theString, java.lang.String thePattern)
      Is string valid date?
      Parameters:
      theString - date string
      thePattern - pattern (null = standard pattern)
      Returns:
      valid date?
      Since:
      0.9.7
    • isValidDate

      public static boolean isValidDate​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
      Is string valid date?
      Parameters:
      theString - date string
      theFormatter - formatter (null = standard formatter)
      Returns:
      valid date?
      Since:
      0.12.0
    • parseTime

      public static java.time.LocalTime parseTime​(java.lang.String theString)
      Parse time with standard pattern/formatter.
      Parameters:
      theString - time string
      Returns:
      time
      Since:
      0.12.0
    • parseTime

      public static java.time.LocalTime parseTime​(java.lang.String theString, java.lang.String thePattern)
      Parse time with given pattern.
      Parameters:
      theString - time string
      thePattern - pattern (null = standard pattern)
      Returns:
      time
      Since:
      0.12.0
    • parseTime

      public static java.time.LocalTime parseTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
      Parse time with given formatter.
      Parameters:
      theString - time string
      theFormatter - formatter (null = standard formatter)
      Returns:
      date
      Since:
      0.12.0
    • isValidTime

      public static boolean isValidTime​(java.lang.String theString)
      Is string valid time?
      Parameters:
      theString - time string
      Returns:
      valid time?
      Since:
      0.12.0
    • isValidTime

      public static boolean isValidTime​(java.lang.String theString, java.lang.String thePattern)
      Is string valid time?
      Parameters:
      theString - time string
      thePattern - pattern (null = standard pattern)
      Returns:
      valid time?
      Since:
      0.12.0
    • isValidTime

      public static boolean isValidTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
      Is string valid time?
      Parameters:
      theString - date string
      theFormatter - formatter (null = standard formatter)
      Returns:
      valid time?
      Since:
      0.12.0
    • parseDateTime

      public static java.time.LocalDateTime parseDateTime​(java.lang.String theString)
      Convert text to LocalDateTime.
      Parameters:
      theString - text to convert
      Returns:
      datetime (null if conversion was not successful)
      Since:
      0.9.1
    • parseDateTime

      public static java.time.LocalDateTime parseDateTime​(java.lang.String theString, java.lang.String thePattern)
      Convert text to LocalDateTime trying pattern and then standard patterns.
      Parameters:
      theString - text to convert
      thePattern - pattern
      Returns:
      datetime (null if conversion was not successful)
      Since:
      0.9.7
    • parseDateTime

      public static java.time.LocalDateTime parseDateTime​(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)
      Convert text to LocalDateTime trying formatter and then standard formatters. TODO this is hacked really badly, because I can't grasp formatters fully.
      Parameters:
      theString - text to convert
      theFormatter - formatter
      Returns:
      datetime (null if conversion was not successful)
      Since:
      0.12.0
    • toDate

      public static java.util.Date toDate​(java.time.LocalDateTime theDateTime)
      Convert LocalDateTime to Date.
      Parameters:
      theDateTime - datetime
      Returns:
      date
    • toDate

      public static java.util.Date toDate​(java.time.LocalDate theDate)
      Convert LocalDate to Date.
      Parameters:
      theDate - date
      Returns:
      date
      Since:
      0.11.0
    • getDateConverter

      public static javafx.util.StringConverter<java.time.LocalDate> getDateConverter()
      Returns date converter e.g. for date pickers with standard pattern.
      Returns:
      date converter
      Since:
      0.11.0
    • getDateConverter

      public static javafx.util.StringConverter<java.time.LocalDate> getDateConverter​(java.lang.String thePattern)
      Returns date converter e.g. for date pickers.
      Parameters:
      thePattern - pattern (null = standard pattern)
      Returns:
      date converter
      Since:
      0.11.0
    • getDateConverter

      public static javafx.util.StringConverter<java.time.LocalDate> getDateConverter​(java.time.format.DateTimeFormatter theFormatter)
      Returns date converter e.g. for date pickers.
      Parameters:
      theFormatter - formatter (null = standard formatter)
      Returns:
      date converter
      Since:
      0.12.0