Top Description Inners Fields Constructors Methods
org.apache.poi.ss.usermodel

public Class DateUtil

extends Object
Class Inheritance
Imports
java.math.BigDecimal, java.time.LocalDate, .LocalDateTime, .LocalTime, .ZoneId, java.time.format.DateTimeFormatter, .DateTimeFormatterBuilder, java.time.temporal.ChronoField, .ChronoUnit, .TemporalAccessor, .TemporalQueries, java.util.Calendar, .Date, .TimeZone, java.util.regex.Pattern, org.apache.poi.ss.formula.ConditionalFormattingEvaluator, org.apache.poi.util.LocaleUtil, .ThreadLocalUtil

Contains methods for dealing with Excel dates.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final BigDecimal
private static final BigDecimal
private static final BigDecimal
private static final Pattern
date_ptrn1

The following patterns are used in isADateFormat(int, String)

private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final DateTimeFormatter
public static final long
public static final int
private static final ThreadLocal<Boolean>
private static final ThreadLocal<Integer>
private static final ThreadLocal<String>
public static final int
public static final int
public static final int
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected static int

Returns:

days number of days since 1900/12/31
absoluteDay
(Calendar
the Calendar
cal
,
boolean use1904windowing)

Given a Calendar, return the number of days since 1900/12/31.

protected static int

Returns:

days number of days since 1900/12/31
absoluteDay
(LocalDateTime
the Date
date
,
boolean use1904windowing)

Given a LocalDateTime, return the number of days since 1900/12/31.

private static int

Returns:

days number of days since 1900/12/31
absoluteDay
(int
the year
year
,
int
the day of the year
dayOfYear
,
boolean use1904windowing)

Given a year and day of year, return the number of days since 1900/12/31.

private static void
cache(String formatString, int formatIndex, boolean cached)

public static double

Returns:

a double between 0 and 1 representing the fraction of the day
convertTime
(String timeStr)

Converts a string of format "HH:MM" or "HH:MM:SS" to its (Excel) numeric equivalent

private static double
pack-priv static int

Returns:

days number of days in years prior to yr.
daysInPriorYears
(int
a year (1900 < yr < 4000)
yr
,
boolean
Should 1900 or 1904 date windowing be used?
use1904windowing
)

Return the number of days in prior years since 1900

private static Calendar
dayStart(final Calendar cal)

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(LocalDate
the Date
date
)

Given a LocalDate, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(LocalDate
the Date
date
,
boolean
Should 1900 or 1904 date windowing be used?
use1904windowing
)

Given a LocalDate, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(LocalDateTime
the Date
date
)

Given a LocalDateTime, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(LocalDateTime
the Date
date
,
boolean
Should 1900 or 1904 date windowing be used?
use1904windowing
)

Given a LocalDateTime, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(Date
the 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.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(Date
the Date
date
,
boolean
Should 1900 or 1904 date windowing be used?
use1904windowing
)

Given a Date, converts it into a double representing its internal Excel representation, which is the number of days since 1/1/1900.

public static double

Returns:

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
getExcelDate
(Calendar
the Calendar holding the date to convert
date
,
boolean
Should 1900 or 1904 date windowing be used?
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.

public static Calendar

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaCalendar
(double
The Excel date.
date
)

Get EXCEL date as Java Calendar (with default time zone).

public static Calendar

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaCalendar
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
)

Get EXCEL date as Java Calendar (with default time zone).

public static Calendar

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaCalendar
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
,
TimeZone
The TimeZone to evaluate the date in
timeZone
)

Get EXCEL date as Java Calendar with given time zone.

public static Calendar

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaCalendar
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
,
TimeZone
The TimeZone to evaluate the date in
timeZone
,
boolean
round to closest second
roundSeconds
)

Get EXCEL date as Java Calendar with given time zone.

public static Calendar

Returns:

Java representation of the date in UTC, or null if date is not a valid Excel date
getJavaCalendarUTC
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
)

Get EXCEL date as Java Calendar with UTC time zone.

public static Date

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaDate
(double
The Excel date.
date
,
TimeZone
The TimeZone to evaluate the date in
tz
)

Given an Excel date with using 1900 date windowing, and converts it to a java.util.Date.

public static Date

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaDate
(double
The Excel date.
date
)

Given an Excel date with using 1900 date windowing, and converts it to a java.util.Date.

public static Date

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaDate
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
,
TimeZone
The TimeZone to evaluate the date in
tz
)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date.

public static Date

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaDate
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
,
TimeZone
The TimeZone to evaluate the date in
tz
,
boolean
round to closest second
roundSeconds
)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date.

public static Date

Returns:

Java representation of the date, or null if date is not a valid Excel date
getJavaDate
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date.

public static LocalDateTime

Returns:

Java representation of the date, or null if date is not a valid Excel date
getLocalDateTime
(double
The Excel date.
date
)

Given an Excel date with using 1900 date windowing, and converts it to a java.time.LocalDateTime.

public static LocalDateTime

Returns:

Java representation of the date, or null if date is not a valid Excel date
getLocalDateTime
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.time.LocalDateTime.

public static LocalDateTime

Returns:

Java representation of the date, or null if date is not a valid Excel date
getLocalDateTime
(double
The Excel date.
date
,
boolean
true if date uses 1904 windowing, or false if using 1900 date windowing.
use1904windowing
,
boolean
round to closest second
roundSeconds
)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.time.LocalDateTime.

private static double
internalGetExcelDate(int year, int dayOfYear, int hour, int minute, int second, int milliSecond, boolean use1904windowing)

public static boolean

Returns:

true if it is a valid date format, false if not or null
isADateFormat
(ExcelNumberFormat
The number format index and string expression, or null if not specified
numFmt
)

Given a format ID and its format String, will check to see if the format represents a date format or not.

public static boolean

Returns:

true if it is a valid date format, false if not or null
isADateFormat
(int
The index of the format, eg from ExtendedFormatRecord.getFormatIndex
formatIndex
,
String
The format string, eg from FormatRecord.getFormatString
formatString
)

Given a format ID and its format String, will check to see if the format represents a date format or not.

private static boolean
isCached(String formatString, int formatIndex)

public static boolean

Returns:

true if it looks like a date
isCellDateFormatted
(Cell
The cell to look at
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.

public static boolean

Returns:

true if it looks like a date
isCellDateFormatted
(Cell
The cell to look at
cell
,
ConditionalFormattingEvaluator
if available, or null
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.

public static boolean
isCellInternalDateFormatted(Cell cell)

Check if a cell contains a date, checking only for internal excel date formats.

public static boolean
isInternalDateFormat(int format)

Given a format ID this will check whether the format represents an internal excel date format or not.

public static boolean

Returns:

true if valid
isValidExcelDate
(double
the double value
value
)

Given a double, checks if it is a valid Excel date.

public static Double
private static int
parseInt(String strVal, String fieldName, int rangeMax)

private static int
parseInt(String strVal, String fieldName, int lowerLimit, int upperLimit)

public static Date

Returns:

a double representing the (integer) number of days since the start of the Excel epoch
parseYYYYMMDDDate
(String dateStr)

Converts a string of format "YYYY/MM/DD" to its (Excel) numeric equivalent

private static Date
public static void
setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing, boolean roundSeconds)

public static LocalDateTime

Returns:

LocalDateTime instance
toLocalDateTime
(Date
the date
date
)

Convert a Java Date (at UTC) to LocalDateTime.

public static LocalDateTime

Returns:

LocalDateTime instance
toLocalDateTime
(Calendar
the date
date
)

Convert a Java Calendar (at UTC) to LocalDateTime.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BAD_DATEback to summary
private static final int BAD_DATE
BD_MILISEC_RNDback to summary
private static final BigDecimal BD_MILISEC_RND
BD_NANOSEC_DAYback to summary
private static final BigDecimal BD_NANOSEC_DAY
BD_SECOND_RNDback to summary
private static final BigDecimal BD_SECOND_RND
date_ptrn1back to summary
private static final Pattern date_ptrn1

The following patterns are used in isADateFormat(int, String)

date_ptrn2back to summary
private static final Pattern date_ptrn2
date_ptrn3aback to summary
private static final Pattern date_ptrn3a
date_ptrn3bback to summary
private static final Pattern date_ptrn3b
date_ptrn4back to summary
private static final Pattern date_ptrn4
date_ptrn5back to summary
private static final Pattern date_ptrn5
dateTimeFormatsback to summary
private static final DateTimeFormatter dateTimeFormats
DAY_MILLISECONDSback to summary
public static final long DAY_MILLISECONDS
HOURS_PER_DAYback to summary
public static final int HOURS_PER_DAY
lastCachedResultback to summary
private static final ThreadLocal<Boolean> lastCachedResult
lastFormatIndexback to summary
private static final ThreadLocal<Integer> lastFormatIndex
lastFormatStringback to summary
private static final ThreadLocal<String> lastFormatString
MINUTES_PER_HOURback to summary
public static final int MINUTES_PER_HOUR
SECONDS_PER_DAYback to summary
public static final int SECONDS_PER_DAY
SECONDS_PER_MINUTEback to summary
public static final int SECONDS_PER_MINUTE
TIME_SEPARATOR_PATTERNback to summary
private static final Pattern TIME_SEPARATOR_PATTERN

Constructor Detail

DateUtilback to summary
private DateUtil()

Method Detail

absoluteDayback to summary
protected static int absoluteDay(Calendar cal, boolean use1904windowing)

Given a Calendar, return the number of days since 1900/12/31.

Parameters
cal:Calendar

the Calendar

Returns:int

days number of days since 1900/12/31

Exceptions
IllegalArgumentException:
if date is invalid
absoluteDayback to summary
protected static int absoluteDay(LocalDateTime date, boolean use1904windowing)

Given a LocalDateTime, return the number of days since 1900/12/31.

Parameters
date:LocalDateTime

the Date

Returns:int

days number of days since 1900/12/31

Exceptions
IllegalArgumentException:
if date is invalid
absoluteDayback to summary
private static int absoluteDay(int year, int dayOfYear, boolean use1904windowing)

Given a year and day of year, return the number of days since 1900/12/31.

Parameters
year:int

the year

dayOfYear:int

the day of the year

Returns:int

days number of days since 1900/12/31

Exceptions
IllegalArgumentException:
if date is invalid
cacheback to summary
private static void cache(String formatString, int formatIndex, boolean cached)
convertTimeback to summary
public static double convertTime(String timeStr)

Converts a string of format "HH:MM" or "HH:MM:SS" to its (Excel) numeric equivalent

Returns:double

a double between 0 and 1 representing the fraction of the day

convertTimeInternalback to summary
private static double convertTimeInternal(String timeStr) throws FormatException
daysInPriorYearsback to summary
pack-priv static int daysInPriorYears(int yr, boolean use1904windowing)

Return the number of days in prior years since 1900

Parameters
yr:int

a year (1900 < yr < 4000)

use1904windowing:boolean

Should 1900 or 1904 date windowing be used?

Returns:int

days number of days in years prior to yr.

Exceptions
IllegalArgumentException:
if year is outside of range.
dayStartback to summary
private static Calendar dayStart(final Calendar cal)
getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:LocalDate

the Date

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:LocalDate

the Date

use1904windowing:boolean

Should 1900 or 1904 date windowing be used?

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:LocalDateTime

the Date

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:LocalDateTime

the Date

use1904windowing:boolean

Should 1900 or 1904 date windowing be used?

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:Date

the Date

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:Date

the Date

use1904windowing:boolean

Should 1900 or 1904 date windowing be used?

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getExcelDateback to summary
public static double getExcelDate(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. Fractional days represent hours, minutes, and seconds.

Parameters
date:Calendar

the Calendar holding the date to convert

use1904windowing:boolean

Should 1900 or 1904 date windowing be used?

Returns:double

Excel representation of Date (-1 if error - test for error by checking for less than 0.1)

getJavaCalendarback to summary
public static Calendar getJavaCalendar(double date)

Get EXCEL date as Java Calendar (with default time zone). This is like getJavaDate(double) but returns a Calendar object.

Parameters
date:double

The Excel date.

Returns:Calendar

Java representation of the date, or null if date is not a valid Excel date

getJavaCalendarback to summary
public static Calendar getJavaCalendar(double date, boolean use1904windowing)

Get EXCEL date as Java Calendar (with default time zone). This is like getJavaDate(double, boolean) but returns a Calendar object.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

Returns:Calendar

Java representation of the date, or null if date is not a valid Excel date

getJavaCalendarback to summary
public static Calendar getJavaCalendar(double date, boolean use1904windowing, TimeZone timeZone)

Get EXCEL date as Java Calendar with given time zone.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

timeZone:TimeZone

The TimeZone to evaluate the date in

Returns:Calendar

Java representation of the date, or null if date is not a valid Excel date

getJavaCalendarback to summary
public static Calendar getJavaCalendar(double date, boolean use1904windowing, TimeZone timeZone, boolean roundSeconds)

Get EXCEL date as Java Calendar with given time zone.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

timeZone:TimeZone

The TimeZone to evaluate the date in

roundSeconds:boolean

round to closest second

Returns:Calendar

Java representation of the date, or null if date is not a valid Excel date

getJavaCalendarUTCback to summary
public static Calendar getJavaCalendarUTC(double date, boolean use1904windowing)

Get EXCEL date as Java Calendar with UTC time zone. This is similar to getJavaDate(double, boolean) but returns a Calendar object that has UTC as time zone, so no daylight saving hassle.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

Returns:Calendar

Java representation of the date in UTC, or null if date is not a valid Excel date

getJavaDateback to summary
public static Date getJavaDate(double date, TimeZone tz)

Given an Excel date with using 1900 date windowing, and converts it to a java.util.Date. Excel Dates and Times are stored without any timezone information. If you know (through other means) that your file uses a different TimeZone to the system default, you can use this version of the getJavaDate() method to handle it.

Parameters
date:double

The Excel date.

tz:TimeZone

The TimeZone to evaluate the date in

Returns:Date

Java representation of the date, or null if date is not a valid Excel date

getJavaDateback to summary
public static Date getJavaDate(double date)

Given an Excel date with using 1900 date windowing, and converts it to a java.util.Date.

Note

If the default 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 time

Parameters
date:double

The Excel date.

Returns:Date

Java representation of the date, or null if date is not a valid Excel date

See Also
java.util.TimeZone
getJavaDateback to summary
public static Date getJavaDate(double date, boolean use1904windowing, TimeZone tz)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date. Excel Dates and Times are stored without any timezone information. If you know (through other means) that your file uses a different TimeZone to the system default, you can use this version of the getJavaDate() method to handle it.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

tz:TimeZone

The TimeZone to evaluate the date in

Returns:Date

Java representation of the date, or null if date is not a valid Excel date

getJavaDateback to summary
public static Date getJavaDate(double date, boolean use1904windowing, TimeZone tz, boolean roundSeconds)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date. Excel Dates and Times are stored without any timezone information. If you know (through other means) that your file uses a different TimeZone to the system default, you can use this version of the getJavaDate() method to handle it.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

tz:TimeZone

The TimeZone to evaluate the date in

roundSeconds:boolean

round to closest second

Returns:Date

Java representation of the date, or null if date is not a valid Excel date

getJavaDateback to summary
public static Date getJavaDate(double date, boolean use1904windowing)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.util.Date.

Note

If the default 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 time

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

Returns:Date

Java representation of the date, or null if date is not a valid Excel date

See Also
java.util.TimeZone
getLocalDateTimeback to summary
public static LocalDateTime getLocalDateTime(double date)

Given an Excel date with using 1900 date windowing, and converts it to a java.time.LocalDateTime.

Note

If the default 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 time

Parameters
date:double

The Excel date.

Returns:LocalDateTime

Java representation of the date, or null if date is not a valid Excel date

See Also
java.util.TimeZone
getLocalDateTimeback to summary
public static LocalDateTime getLocalDateTime(double date, boolean use1904windowing)

Given an Excel date with either 1900 or 1904 date windowing, converts it to a java.time.LocalDateTime. Excel Dates and Times are stored without any timezone information. If you know (through other means) that your file uses a different TimeZone to the system default, you can use this version of the getJavaDate() method to handle it.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

Returns:LocalDateTime

Java representation of the date, or null if date is not a valid Excel date

getLocalDateTimeback to summary
public static 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. Excel Dates and Times are stored without any timezone information. If you know (through other means) that your file uses a different TimeZone to the system default, you can use this version of the getJavaDate() method to handle it.

Parameters
date:double

The Excel date.

use1904windowing:boolean

true if date uses 1904 windowing, or false if using 1900 date windowing.

roundSeconds:boolean

round to closest second

Returns:LocalDateTime

Java representation of the date, or null if date is not a valid Excel date

Annotations
@SuppressWarnings:squid:S2111
internalGetExcelDateback to summary
private static double internalGetExcelDate(int year, int dayOfYear, int hour, int minute, int second, int milliSecond, boolean use1904windowing)
isADateFormatback to summary
public 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. Firstly, it will check to see if the format ID corresponds to an internal excel date format (eg most US date formats) If not, it will check to see if the format string only contains date formatting characters (ymd-/), which covers most non US date formats.

Parameters
numFmt:ExcelNumberFormat

The number format index and string expression, or null if not specified

Returns:boolean

true if it is a valid date format, false if not or null

See Also
isInternalDateFormat(int)
isADateFormatback to summary
public static boolean isADateFormat(int formatIndex, String formatString)

Given a format ID and its format String, will check to see if the format represents a date format or not. Firstly, it will check to see if the format ID corresponds to an internal excel date format (eg most US date formats) If not, it will check to see if the format string only contains date formatting characters (ymd-/), which covers most non US date formats.

Parameters
formatIndex:int

The index of the format, eg from ExtendedFormatRecord.getFormatIndex

formatString:String

The format string, eg from FormatRecord.getFormatString

Returns:boolean

true if it is a valid date format, false if not or null

See Also
isInternalDateFormat(int)
isCachedback to summary
private static boolean isCached(String formatString, int formatIndex)
isCellDateFormattedback to summary
public 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.

Parameters
cell:Cell

The cell to look at

Returns:boolean

true if it looks like a date

See Also
isADateFormat(int, String), isInternalDateFormat(int)
isCellDateFormattedback to summary
public 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. Format is determined from applicable conditional formatting, if any, or cell style.

Parameters
cell:Cell

The cell to look at

cfEvaluator:ConditionalFormattingEvaluator

if available, or null

Returns:boolean

true if it looks like a date

See Also
isADateFormat(int, String), isInternalDateFormat(int)
isCellInternalDateFormattedback to summary
public static boolean isCellInternalDateFormatted(Cell cell)

Check if a cell contains a date, checking only for internal excel date formats. As Excel stores a great many of its dates in "non-internal" date formats, you will not normally want to use this method.

See Also
isADateFormat(int, String), isInternalDateFormat(int)
isInternalDateFormatback to summary
public static boolean isInternalDateFormat(int format)

Given a format ID this will check whether the format represents an internal excel date format or not.

See Also
isADateFormat(int, java.lang.String)
isValidExcelDateback to summary
public static boolean isValidExcelDate(double value)

Given a double, checks if it is a valid Excel date.

Parameters
value:double

the double value

Returns:boolean

true if valid

parseDateTimeback to summary
public static Double parseDateTime(String str)
parseIntback to summary
private static int parseInt(String strVal, String fieldName, int rangeMax) throws FormatException
parseIntback to summary
private static int parseInt(String strVal, String fieldName, int lowerLimit, int upperLimit) throws FormatException
parseYYYYMMDDDateback to summary
public static Date parseYYYYMMDDDate(String dateStr)

Converts a string of format "YYYY/MM/DD" to its (Excel) numeric equivalent

Returns:Date

a double representing the (integer) number of days since the start of the Excel epoch

parseYYYYMMDDDateInternalback to summary
private static Date parseYYYYMMDDDateInternal(String timeStr) throws FormatException
setCalendarback to summary
public static void setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing, boolean roundSeconds)
toLocalDateTimeback to summary
public static LocalDateTime toLocalDateTime(Date date)

Convert a Java Date (at UTC) to LocalDateTime.

Parameters
date:Date

the date

Returns:LocalDateTime

LocalDateTime instance

toLocalDateTimeback to summary
public static LocalDateTime toLocalDateTime(Calendar date)

Convert a Java Calendar (at UTC) to LocalDateTime.

Parameters
date:Calendar

the date

Returns:LocalDateTime

LocalDateTime instance

org.apache.poi.ss.usermodel back to summary

private final Class DateUtil.FormatException

extends Exception
Class Inheritance
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
public

Constructor Detail

FormatExceptionback to summary
public FormatException(String msg)