public class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static long |
DAY_MILLISECONDS |
static int |
HOURS_PER_DAY |
static int |
MINUTES_PER_HOUR |
static int |
SECONDS_PER_DAY |
static int |
SECONDS_PER_MINUTE |
Modifier and Type | Method and Description |
---|---|
protected static int |
absoluteDay(java.util.Calendar cal,
boolean use1904windowing)
Given a Calendar, return the number of days since 1900/12/31.
|
protected static int |
absoluteDay(java.time.LocalDateTime date,
boolean use1904windowing)
Given a LocalDateTime, return the number of days since 1900/12/31.
|
static double |
convertTime(java.lang.String timeStr)
Converts a string of format "HH:MM" or "HH:MM:SS" to its (Excel) numeric equivalent
|
static double |
getExcelDate(java.util.Calendar date,
boolean use1904windowing)
Given a Date in the form of a Calendar, converts it into a double
representing its internal Excel representation, which is the
number of days since 1/1/1900.
|
static double |
getExcelDate(java.util.Date date)
Given a Date, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static double |
getExcelDate(java.util.Date date,
boolean use1904windowing)
Given a Date, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static double |
getExcelDate(java.time.LocalDate date)
Given a LocalDate, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static double |
getExcelDate(java.time.LocalDate date,
boolean use1904windowing)
Given a LocalDate, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static double |
getExcelDate(java.time.LocalDateTime date)
Given a LocalDateTime, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static double |
getExcelDate(java.time.LocalDateTime date,
boolean use1904windowing)
Given a LocalDateTime, converts it into a double representing its internal Excel representation,
which is the number of days since 1/1/1900.
|
static java.util.Calendar |
getJavaCalendar(double date)
Get EXCEL date as Java Calendar (with default time zone).
|
static java.util.Calendar |
getJavaCalendar(double date,
boolean use1904windowing)
Get EXCEL date as Java Calendar (with default time zone).
|
static java.util.Calendar |
getJavaCalendar(double date,
boolean use1904windowing,
java.util.TimeZone timeZone)
Get EXCEL date as Java Calendar with given time zone.
|
static java.util.Calendar |
getJavaCalendar(double date,
boolean use1904windowing,
java.util.TimeZone timeZone,
boolean roundSeconds)
Get EXCEL date as Java Calendar with given time zone.
|
static java.util.Calendar |
getJavaCalendarUTC(double date,
boolean use1904windowing)
Get EXCEL date as Java Calendar with UTC time zone.
|
static java.util.Date |
getJavaDate(double date)
Given an Excel date with using 1900 date windowing, and
converts it to a java.util.Date.
|
static java.util.Date |
getJavaDate(double date,
boolean use1904windowing)
Given an Excel date with either 1900 or 1904 date windowing,
converts it to a java.util.Date.
|
static java.util.Date |
getJavaDate(double date,
boolean use1904windowing,
java.util.TimeZone tz)
Given an Excel date with either 1900 or 1904 date windowing,
converts it to a java.util.Date.
|
static java.util.Date |
getJavaDate(double date,
boolean use1904windowing,
java.util.TimeZone tz,
boolean roundSeconds)
Given an Excel date with either 1900 or 1904 date windowing,
converts it to a java.util.Date.
|
static java.util.Date |
getJavaDate(double date,
java.util.TimeZone tz)
Given an Excel date with using 1900 date windowing, and
converts it to a java.util.Date.
|
static java.time.LocalDateTime |
getLocalDateTime(double date)
Given an Excel date with using 1900 date windowing, and
converts it to a java.time.LocalDateTime.
|
static java.time.LocalDateTime |
getLocalDateTime(double date,
boolean use1904windowing)
Given an Excel date with either 1900 or 1904 date windowing,
converts it to a java.time.LocalDateTime.
|
static java.time.LocalDateTime |
getLocalDateTime(double date,
boolean use1904windowing,
boolean roundSeconds)
Given an Excel date with either 1900 or 1904 date windowing,
converts it to a java.time.LocalDateTime.
|
static boolean |
isADateFormat(ExcelNumberFormat numFmt)
Given a format ID and its format String, will check to see if the
format represents a date format or not.
|
static boolean |
isADateFormat(int formatIndex,
java.lang.String formatString)
Given a format ID and its format String, will check to see if the
format represents a date format or not.
|
static boolean |
isCellDateFormatted(Cell cell)
Check if a cell contains a date
Since dates are stored internally in Excel as double values
we infer it is a date if it is formatted as such.
|
static boolean |
isCellDateFormatted(Cell cell,
ConditionalFormattingEvaluator cfEvaluator)
Check if a cell contains a date
Since dates are stored internally in Excel as double values
we infer it is a date if it is formatted as such.
|
static boolean |
isCellInternalDateFormatted(Cell cell)
Check if a cell contains a date, checking only for internal
excel date formats.
|
static boolean |
isInternalDateFormat(int format)
Given a format ID this will check whether the format represents
an internal excel date format or not.
|
static boolean |
isValidExcelDate(double value)
Given a double, checks if it is a valid Excel date.
|
static java.lang.Double |
parseDateTime(java.lang.String str) |
static java.util.Date |
parseYYYYMMDDDate(java.lang.String dateStr)
Converts a string of format "YYYY/MM/DD" to its (Excel) numeric equivalent
|
static void |
setCalendar(java.util.Calendar calendar,
int wholeDays,
int millisecondsInDay,
boolean use1904windowing,
boolean roundSeconds) |
static java.time.LocalDateTime |
toLocalDateTime(java.util.Calendar date)
Convert a Java Calendar (at UTC) to LocalDateTime.
|
static java.time.LocalDateTime |
toLocalDateTime(java.util.Date date)
Convert a Java Date (at UTC) to LocalDateTime.
|
public static final int SECONDS_PER_MINUTE
public static final int MINUTES_PER_HOUR
public static final int HOURS_PER_DAY
public static final int SECONDS_PER_DAY
public static final long DAY_MILLISECONDS
public static java.time.LocalDateTime toLocalDateTime(java.util.Date date)
date
- the datepublic static java.time.LocalDateTime toLocalDateTime(java.util.Calendar date)
date
- the datepublic static double getExcelDate(java.time.LocalDate date)
date
- the Datepublic static double getExcelDate(java.time.LocalDate date, boolean use1904windowing)
date
- the Dateuse1904windowing
- Should 1900 or 1904 date windowing be used?public static double getExcelDate(java.time.LocalDateTime date)
date
- the Datepublic static double getExcelDate(java.time.LocalDateTime date, boolean use1904windowing)
date
- the Dateuse1904windowing
- Should 1900 or 1904 date windowing be used?public static double getExcelDate(java.util.Date date)
date
- the Datepublic static double getExcelDate(java.util.Date date, boolean use1904windowing)
date
- the Dateuse1904windowing
- Should 1900 or 1904 date windowing be used?public static double getExcelDate(java.util.Calendar date, boolean use1904windowing)
date
- the Calendar holding the date to convertuse1904windowing
- Should 1900 or 1904 date windowing be used?public static java.util.Date getJavaDate(double date, java.util.TimeZone tz)
date
- The Excel date.tz
- The TimeZone to evaluate the date inpublic static java.util.Date getJavaDate(double date)
TimeZone
in Java uses Daylight
Saving Time then the conversion back to an Excel date may not give
the same value, that is the comparison
excelDate == getExcelDate(getJavaDate(excelDate,false))
is not always true. For example if default timezone is
Europe/Copenhagen
, on 2004-03-28 the minute after
01:59 CET is 03:00 CEST, if the excel date represents a time between
02:00 and 03:00 then it is converted to past 03:00 summer timedate
- The Excel date.TimeZone
public static java.util.Date getJavaDate(double date, boolean use1904windowing, java.util.TimeZone tz)
date
- The Excel date.tz
- The TimeZone to evaluate the date inuse1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.public static java.util.Date getJavaDate(double date, boolean use1904windowing, java.util.TimeZone tz, boolean roundSeconds)
date
- The Excel date.tz
- The TimeZone to evaluate the date inuse1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.roundSeconds
- round to closest secondpublic static java.util.Date getJavaDate(double date, boolean use1904windowing)
TimeZone
in Java uses Daylight
Saving Time then the conversion back to an Excel date may not give
the same value, that is the comparison
excelDate == getExcelDate(getJavaDate(excelDate,false))
is not always true. For example if default timezone is
Europe/Copenhagen
, on 2004-03-28 the minute after
01:59 CET is 03:00 CEST, if the excel date represents a time between
02:00 and 03:00 then it is converted to past 03:00 summer timedate
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.TimeZone
public static java.time.LocalDateTime getLocalDateTime(double date)
TimeZone
in Java uses Daylight
Saving Time then the conversion back to an Excel date may not give
the same value, that is the comparison
excelDate == getExcelDate(getLocalDateTime(excelDate,false))
is not always true. For example if default timezone is
Europe/Copenhagen
, on 2004-03-28 the minute after
01:59 CET is 03:00 CEST, if the excel date represents a time between
02:00 and 03:00 then it is converted to past 03:00 summer timedate
- The Excel date.TimeZone
public static java.time.LocalDateTime getLocalDateTime(double date, boolean use1904windowing)
date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.public static java.time.LocalDateTime getLocalDateTime(double date, boolean use1904windowing, boolean roundSeconds)
date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.roundSeconds
- round to closest secondpublic static void setCalendar(java.util.Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing, boolean roundSeconds)
public static java.util.Calendar getJavaCalendar(double date)
getJavaDate(double)
but returns a Calendar object.date
- The Excel date.public static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing)
getJavaDate(double, boolean)
but returns a Calendar object.date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.public static java.util.Calendar getJavaCalendarUTC(double date, boolean use1904windowing)
getJavaDate(double, boolean)
but returns a
Calendar object that has UTC as time zone, so no daylight saving hassle.date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.public static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing, java.util.TimeZone timeZone)
date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.timeZone
- The TimeZone to evaluate the date inpublic static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing, java.util.TimeZone timeZone, boolean roundSeconds)
date
- The Excel date.use1904windowing
- true if date uses 1904 windowing,
or false if using 1900 date windowing.timeZone
- The TimeZone to evaluate the date inroundSeconds
- round to closest secondpublic static boolean isADateFormat(ExcelNumberFormat numFmt)
numFmt
- The number format index and string expression, or null if not specifiedisInternalDateFormat(int)
public static boolean isADateFormat(int formatIndex, java.lang.String formatString)
formatIndex
- The index of the format, eg from ExtendedFormatRecord.getFormatIndexformatString
- The format string, eg from FormatRecord.getFormatStringisInternalDateFormat(int)
public static boolean isInternalDateFormat(int format)
isADateFormat(int, java.lang.String)
public static boolean isCellDateFormatted(Cell cell)
cell
- The cell to look atisADateFormat(int, String)
,
isInternalDateFormat(int)
public static boolean isCellDateFormatted(Cell cell, ConditionalFormattingEvaluator cfEvaluator)
cell
- The cell to look atcfEvaluator
- if available, or nullisADateFormat(int, String)
,
isInternalDateFormat(int)
public static boolean isCellInternalDateFormatted(Cell cell)
public static boolean isValidExcelDate(double value)
value
- the double valueprotected static int absoluteDay(java.util.Calendar cal, boolean use1904windowing)
cal
- the Calendarjava.lang.IllegalArgumentException
- if date is invalidprotected static int absoluteDay(java.time.LocalDateTime date, boolean use1904windowing)
date
- the Datejava.lang.IllegalArgumentException
- if date is invalidpublic static double convertTime(java.lang.String timeStr)
public static java.util.Date parseYYYYMMDDDate(java.lang.String dateStr)
public static java.lang.Double parseDateTime(java.lang.String str)
Copyright 2022 The Apache Software Foundation or its licensors, as applicable.