public class SpreadsheetDateUtil extends 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 |
|---|---|
static Calendar |
getJavaCalendar(double date,
TimeZone timeZone,
boolean roundSeconds)
Get EXCEL date as Java Calendar with given time zone.
|
static Date |
getJavaDate(double date)
Given an Spreadsheet date with using 1900 date windowing, and
converts it to a java.util.Date.
|
static Date |
getJavaDate(double date,
TimeZone tz)
Given an Spreadsheet date with using 1900 date windowing, and
converts it to a java.util.Date.
|
static Date |
getJavaDate(double date,
TimeZone tz,
boolean roundSeconds)
Given an Spreadsheet date with either 1900 or 1904 date windowing,
converts it to a java.util.Date.
|
static LocalDateTime |
getLocalDateTime(double date)
Given an Spreadsheet date with using 1900 date windowing, and
converts it to a java.time.LocalDateTime.
|
static LocalDateTime |
getLocalDateTime(double date,
boolean roundSeconds)
Given an Spreadsheet date with either 1900 or 1904 date windowing,
converts it to a java.time.LocalDateTime.
|
static double |
getSpreadsheetDate(Date date)
Given a Date, converts it into a double representing its internal Spreadsheet representation,
which is the number of days since 1/1/1900.
|
static double |
getSpreadsheetDate(LocalDate date)
Given a LocalDate, converts it into a double representing its internal Spreadsheet representation,
which is the number of days since 1/1/1900.
|
static double |
getSpreadsheetDate(LocalDateTime date)
Given a LocalDateTime, converts it into a double representing its internal Spreadsheet representation,
which is the number of days since 1/1/1900.
|
static boolean |
isValidSpreadsheetDate(double value)
Given a double, checks if it is a valid Spreadsheet date.
|
static void |
setCalendar(Calendar calendar,
int wholeDays,
int millisecondsInDay,
boolean roundSeconds) |
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 double getSpreadsheetDate(LocalDate date)
date - the Datepublic static double getSpreadsheetDate(LocalDateTime date)
date - the Datepublic static double getSpreadsheetDate(Date date)
date - the Datepublic static Date getJavaDate(double date, TimeZone tz)
Spreadsheet 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.
date - The Spreadsheet date.tz - The TimeZone to evaluate the date inpublic static Date getJavaDate(double date)
NOTE: If the default TimeZone in Java uses Daylight
Saving Time then the conversion back to an Spreadsheet date may not give
the same value, that is the comparison
excelDate == getSpreadsheetDate(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
date - The Spreadsheet date.TimeZonepublic static Date getJavaDate(double date, TimeZone tz, boolean roundSeconds)
Spreadsheet 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.
date - The Spreadsheet date.tz - The TimeZone to evaluate the date inroundSeconds - round to closest secondpublic static LocalDateTime getLocalDateTime(double date)
NOTE: If the default TimeZone in Java uses Daylight
Saving Time then the conversion back to an Spreadsheet date may not give
the same value, that is the comparison
excelDate == getSpreadsheetDate(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
date - The Spreadsheet date.TimeZonepublic static LocalDateTime getLocalDateTime(double date, boolean roundSeconds)
Spreadsheet 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.
date - The Spreadsheet date.roundSeconds - round to closest secondpublic static Calendar getJavaCalendar(double date, TimeZone timeZone, boolean roundSeconds)
date - The Spreadsheet date.timeZone - The TimeZone to evaluate the date inroundSeconds - round to closest secondpublic static void setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean roundSeconds)
public static boolean isValidSpreadsheetDate(double value)
value - the double valueCopyright © 2022. All rights reserved.