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.StringDATE_PATTERNStandard pattern for dates.static java.lang.StringDATETIME_PATTERNStandard pattern for datetimes.static java.lang.StringTIME_PATTERNStandard pattern for times. -
Constructor Summary
Constructors Constructor Description DateTimeUtils() -
Method Summary
Modifier and Type Method Description static java.lang.StringformatDate(java.time.LocalDate theDate)FormatLocalDatewith standard pattern/formatter.static java.lang.StringformatDate(java.time.LocalDate theDate, java.lang.String thePattern)FormatLocalDatewith given pattern.static java.lang.StringformatDate(java.time.LocalDate theDate, java.time.format.DateTimeFormatter theFormatter)FormatLocalDatewith given formatter.static java.lang.StringformatDateTime(java.time.LocalDateTime theDateTime)FormatLocalDateTimewith standard pattern/formatter.static java.lang.StringformatDateTime(java.time.LocalDateTime theDateTime, java.lang.String thePattern)FormatLocalDateTimewith given pattern.static java.lang.StringformatDateTime(java.time.LocalDateTime theDateTime, java.time.format.DateTimeFormatter theFormatter)FormatLocalDateTimewith given formatter.static java.lang.StringformatDateTimeAsDate(java.time.LocalDateTime theDateTime)Format datetime as date.static java.lang.StringformatDateTimeAsTime(java.time.LocalDateTime theDateTime)Format datetime as time.static java.lang.StringformatTemporalAccessor(java.time.temporal.TemporalAccessor theAccessor)FormatTemporalAccessorwith standard pattern/formatter.static java.lang.StringformatTemporalAccessor(java.time.temporal.TemporalAccessor theAccessor, java.lang.String thePattern)FormatTemporalAccessorwith given pattern.static java.lang.StringformatTemporalAccessor(java.time.temporal.TemporalAccessor theAccessor, java.time.format.DateTimeFormatter theFormatter)FormatTemporalAccessorwith givenDateTimeFormatter.static java.lang.StringformatTime(java.time.LocalTime theTime)FormatLocalTimewith standard pattern/formatter.static java.lang.StringformatTime(java.time.LocalTime theTime, java.lang.String thePattern)FormatLocalTimewith given pattern.static java.lang.StringformatTime(java.time.LocalTime theTime, java.time.format.DateTimeFormatter theFormatter)FormatLocalTimewith 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 booleanisValidDate(java.lang.String theString)Is string valid date?static booleanisValidDate(java.lang.String theString, java.lang.String thePattern)Is string valid date?static booleanisValidDate(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)Is string valid date?static booleanisValidTime(java.lang.String theString)Is string valid time?static booleanisValidTime(java.lang.String theString, java.lang.String thePattern)Is string valid time?static booleanisValidTime(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)Is string valid time?static java.time.LocalDateparseDate(java.lang.String theString)Parse date with standard pattern/formatter.static java.time.LocalDateparseDate(java.lang.String theString, java.lang.String thePattern)Parse date with given pattern.static java.time.LocalDateparseDate(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)Parse date with given formatter.static java.time.LocalDateTimeparseDateTime(java.lang.String theString)Convert text toLocalDateTime.static java.time.LocalDateTimeparseDateTime(java.lang.String theString, java.lang.String thePattern)Convert text toLocalDateTimetrying pattern and then standard patterns.static java.time.LocalDateTimeparseDateTime(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)Convert text toLocalDateTimetrying formatter and then standard formatters.static java.time.LocalTimeparseTime(java.lang.String theString)Parse time with standard pattern/formatter.static java.time.LocalTimeparseTime(java.lang.String theString, java.lang.String thePattern)Parse time with given pattern.static java.time.LocalTimeparseTime(java.lang.String theString, java.time.format.DateTimeFormatter theFormatter)Parse time with given formatter.static java.util.DatetoDate(java.time.LocalDate theDate)ConvertLocalDatetoDate.static java.util.DatetoDate(java.time.LocalDateTime theDateTime)ConvertLocalDateTimetoDate.
-
Field Details
-
DATE_PATTERN
public static final java.lang.String DATE_PATTERNStandard pattern for dates.- Since:
- 0.9.2
- See Also:
- Constant Field Values
-
TIME_PATTERN
public static final java.lang.String TIME_PATTERNStandard pattern for times.- Since:
- 0.9.7
- See Also:
- Constant Field Values
-
DATETIME_PATTERN
public static final java.lang.String DATETIME_PATTERNStandard pattern for datetimes.- Since:
- 0.9.7
-
-
Constructor Details
-
DateTimeUtils
public DateTimeUtils()
-
-
Method Details
-
formatTemporalAccessor
public static java.lang.String formatTemporalAccessor(java.time.temporal.TemporalAccessor theAccessor)FormatTemporalAccessorwith 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)FormatTemporalAccessorwith given pattern.- Parameters:
theAccessor- accessorthePattern- 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)FormatTemporalAccessorwith givenDateTimeFormatter.- Parameters:
theAccessor- accessortheFormatter- formatter (null = standard formatter)- Returns:
- formatted accessor
- Since:
- 0.12.0
-
formatDate
public static java.lang.String formatDate(java.time.LocalDate theDate)FormatLocalDatewith 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)FormatLocalDatewith given pattern.- Parameters:
theDate- datethePattern- 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)FormatLocalDatewith given formatter.- Parameters:
theDate- datetheFormatter- formatter (null = standard formatter)- Returns:
- formatted date
- Since:
- 0.12.0
-
formatDateTime
public static java.lang.String formatDateTime(java.time.LocalDateTime theDateTime)FormatLocalDateTimewith 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)FormatLocalDateTimewith given pattern.- Parameters:
theDateTime- datetimethePattern- 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)FormatLocalDateTimewith given formatter.- Parameters:
theDateTime- datetimetheFormatter- formatter (null = standard formatter)- Returns:
- formatted datetime
- Since:
- 0.12.0
-
formatTime
public static java.lang.String formatTime(java.time.LocalTime theTime)FormatLocalTimewith 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)FormatLocalTimewith given pattern.- Parameters:
theTime- timethePattern- 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)FormatLocalTimewith given formatter.- Parameters:
theTime- timetheFormatter- 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 stringthePattern- 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 stringtheFormatter- 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 stringthePattern- 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 stringtheFormatter- 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 stringthePattern- 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 stringtheFormatter- 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 stringthePattern- 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 stringtheFormatter- formatter (null = standard formatter)- Returns:
- valid time?
- Since:
- 0.12.0
-
parseDateTime
public static java.time.LocalDateTime parseDateTime(java.lang.String theString)Convert text toLocalDateTime.- 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 toLocalDateTimetrying pattern and then standard patterns.- Parameters:
theString- text to convertthePattern- 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 toLocalDateTimetrying formatter and then standard formatters. TODO this is hacked really badly, because I can't grasp formatters fully.- Parameters:
theString- text to converttheFormatter- formatter- Returns:
- datetime (null if conversion was not successful)
- Since:
- 0.12.0
-
toDate
public static java.util.Date toDate(java.time.LocalDateTime theDateTime)ConvertLocalDateTimetoDate.- Parameters:
theDateTime- datetime- Returns:
- date
-
toDate
public static java.util.Date toDate(java.time.LocalDate theDate)ConvertLocalDatetoDate.- 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
-