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 | Constructor and Description |
---|---|
protected |
DateUtil() |
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.
(给定一个日历,返回自 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.
(给定 LocalDateTime,返回自 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
(将格式为“HH:MM”或“HH:MM:SS”的字符串转换为其 (Excel) 等效数字)
|
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.
(给定日历形式的日期,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个日期,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个日期,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个 LocalDate,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个 LocalDate,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个 LocalDateTime,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
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.
(给定一个 LocalDateTime,将其转换为表示其内部 Excel 表示形式的双精度数,即自 1900 年 1 月 1 日以来的天数。)
|
static java.util.Calendar |
getJavaCalendar(double date)
Get EXCEL date as Java Calendar (with default time zone).
(获取 EXCEL 日期作为 Java 日历(使用默认时区)。)
|
static java.util.Calendar |
getJavaCalendar(double date, boolean use1904windowing)
Get EXCEL date as Java Calendar (with default time zone).
(获取 EXCEL 日期作为 Java 日历(使用默认时区)。)
|
static java.util.Calendar |
getJavaCalendar(double date, boolean use1904windowing, java.util.TimeZone timeZone)
Get EXCEL date as Java Calendar with given time zone.
(获取 EXCEL 日期作为具有给定时区的 Java 日历。)
|
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.
(获取 EXCEL 日期作为具有给定时区的 Java 日历。)
|
static java.util.Calendar |
getJavaCalendarUTC(double date, boolean use1904windowing)
Get EXCEL date as Java Calendar with UTC time zone.
(获取 EXCEL 日期作为具有 UTC 时区的 Java 日历。)
|
static java.util.Date |
getJavaDate(double date)
Given an Excel date with using 1900 date windowing, and converts it to a java.util.Date.
(给定一个使用 1900 日期窗口的 Excel 日期,并将其转换为 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.
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 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.
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 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.
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 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.
(给定一个使用 1900 日期窗口的 Excel 日期,并将其转换为 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.
(给定一个使用 1900 日期窗口的 Excel 日期,并将其转换为 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.
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 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.
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 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.
(给定格式 ID 及其格式字符串,将检查格式是否表示日期格式。)
|
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.
(给定格式 ID 及其格式字符串,将检查格式是否表示日期格式。)
|
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.
(检查单元格是否包含日期 由于日期在 Excel 内部存储为双精度值,因此我们推断它是一个日期,如果它是这样格式化的。)
|
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.
(检查单元格是否包含日期 由于日期在 Excel 内部存储为双精度值,因此我们推断它是一个日期,如果它是这样格式化的。)
|
static boolean |
isCellInternalDateFormatted(Cell cell)
Check if a cell contains a date, checking only for internal excel date formats.
(检查单元格是否包含日期,仅检查内部 excel 日期格式。)
|
static boolean |
isInternalDateFormat(int format)
Given a format ID this will check whether the format represents an internal excel date format or not.
(给定格式 ID,这将检查格式是否代表内部 excel 日期格式。)
|
static boolean |
isValidExcelDate(double value)
Given a double, checks if it is a valid Excel date.
(给定一个双精度,检查它是否是一个有效的 Excel 日期。)
|
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
(将格式为“YYYY/MM/DD”的字符串转换为其 (Excel) 等效数字)
|
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.
(将 Java 日历(UTC 时间)转换为 LocalDateTime。)
|
static java.time.LocalDateTime |
toLocalDateTime(java.util.Date date)
Convert a Java Date (at UTC) to LocalDateTime.
(将 Java 日期(UTC 时间)转换为 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 date
(日期 - 日期)
public static java.time.LocalDateTime toLocalDateTime(java.util.Calendar date)
date
- the date
(日期 - 日期)
public static double getExcelDate(java.time.LocalDate date)
date
- the Date
(日期 - 日期)
public static double getExcelDate(java.time.LocalDate date, boolean use1904windowing)
date
- the Date
(日期 - 日期)
use1904windowing
- Should 1900 or 1904 date windowing be used?
(use1904windowing - 应该使用 1900 还是 1904 日期窗口?)
public static double getExcelDate(java.time.LocalDateTime date)
date
- the Date
(日期 - 日期)
public static double getExcelDate(java.time.LocalDateTime date, boolean use1904windowing)
date
- the Date
(日期 - 日期)
use1904windowing
- Should 1900 or 1904 date windowing be used?
(use1904windowing - 应该使用 1900 还是 1904 日期窗口?)
public static double getExcelDate(java.util.Date date)
date
- the Date
(日期 - 日期)
public static double getExcelDate(java.util.Date date, boolean use1904windowing)
date
- the Date
(日期 - 日期)
use1904windowing
- Should 1900 or 1904 date windowing be used?
(use1904windowing - 应该使用 1900 还是 1904 日期窗口?)
public static double getExcelDate(java.util.Calendar date, boolean use1904windowing)
date
- the Calendar holding the date to convert
(date - 保存要转换的日期的日历)
use1904windowing
- Should 1900 or 1904 date windowing be used?
(use1904windowing - 应该使用 1900 还是 1904 日期窗口?)
public static java.util.Date getJavaDate(double date, java.util.TimeZone tz)
date
- The Excel date.
(日期 - Excel 日期。)
tz
- The TimeZone to evaluate the date in
(tz - 评估日期的时区)
public 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 time
(给定一个使用 1900 日期窗口的 Excel 日期,并将其转换为 java.util.Date。注意:如果 Java 中的默认时区使用夏令时,则转换回 Excel 日期可能不会给出相同的值,即比较 excelDate == getExcelDate(getJavaDate(excelDate,false)) 并不总是正确的。例如,如果默认时区是欧洲/哥本哈根,则在 2004 年 3 月 28 日,欧洲中部时间 01:59 之后的一分钟是 03:00 CEST,如果 excel 日期表示介于 02:00 和 03:00 之间的时间,则将其转换为过去夏令时 03:00)
date
- The Excel date.
(日期 - Excel 日期。)
TimeZone
public static java.util.Date getJavaDate(double date, boolean use1904windowing, java.util.TimeZone tz)
date
- The Excel date.
(日期 - Excel 日期。)
tz
- The TimeZone to evaluate the date in
(tz - 评估日期的时区)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
public static java.util.Date getJavaDate(double date, boolean use1904windowing, java.util.TimeZone tz, boolean roundSeconds)
date
- The Excel date.
(日期 - Excel 日期。)
tz
- The TimeZone to evaluate the date in
(tz - 评估日期的时区)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
roundSeconds
- round to closest second
(roundSeconds - 舍入到最接近的秒)
public 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 time
(给定具有 1900 或 1904 日期窗口的 Excel 日期,将其转换为 java.util.Date。注意:如果 Java 中的默认时区使用夏令时,则转换回 Excel 日期可能不会给出相同的值,即比较 excelDate == getExcelDate(getJavaDate(excelDate,false)) 并不总是正确的。例如,如果默认时区是欧洲/哥本哈根,在 2004 年 3 月 28 日,欧洲中部时间 01:59 之后的分钟是 03:00 CEST,如果 excel 日期表示介于 02:00 和 03:00 之间的时间,则将其转换为过去夏令时 03:00)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
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 time
(给定一个使用 1900 日期窗口的 Excel 日期,并将其转换为 java.time.LocalDateTime。注意:如果 Java 中的默认时区使用夏令时,则转换回 Excel 日期可能不会给出相同的值,即比较 excelDate == getExcelDate(getLocalDateTime(excelDate,false)) 并不总是正确的。例如,如果默认时区是欧洲/哥本哈根,则在 2004 年 3 月 28 日,欧洲中部时间 01:59 之后的一分钟是 03:00 CEST,如果 excel 日期表示介于 02:00 和 03:00 之间的时间,则将其转换为过去夏令时 03:00)
date
- The Excel date.
(日期 - Excel 日期。)
TimeZone
public static java.time.LocalDateTime getLocalDateTime(double date, boolean use1904windowing)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
public static java.time.LocalDateTime getLocalDateTime(double date, boolean use1904windowing, boolean roundSeconds)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
roundSeconds
- round to closest second
(roundSeconds - 舍入到最接近的秒)
public 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.
(获取 EXCEL 日期作为 Java 日历(使用默认时区)。这类似于 getJavaDate(double) 但返回一个 Calendar 对象。)
date
- The Excel date.
(日期 - Excel 日期。)
public static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing)
getJavaDate(double, boolean)
but returns a Calendar object.
(获取 EXCEL 日期作为 Java 日历(使用默认时区)。这类似于 getJavaDate(double, boolean) 但返回一个 Calendar 对象。)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
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.
(获取 EXCEL 日期作为具有 UTC 时区的 Java 日历。这类似于 getJavaDate(double, boolean) 但返回一个以 UTC 作为时区的 Calendar 对象,因此没有夏令时的麻烦。)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
public static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing, java.util.TimeZone timeZone)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
timeZone
- The TimeZone to evaluate the date in
(timeZone - 评估日期的 TimeZone)
public static java.util.Calendar getJavaCalendar(double date, boolean use1904windowing, java.util.TimeZone timeZone, boolean roundSeconds)
date
- The Excel date.
(日期 - Excel 日期。)
use1904windowing
- true if date uses 1904 windowing, or false if using 1900 date windowing.
(use1904windowing - 如果日期使用 1904 窗口,则为 true,如果使用 1900 日期窗口,则为 false。)
timeZone
- The TimeZone to evaluate the date in
(timeZone - 评估日期的 TimeZone)
roundSeconds
- round to closest second
(roundSeconds - 舍入到最接近的秒)
public static boolean isADateFormat(ExcelNumberFormat numFmt)
numFmt
- The number format index and string expression, or null if not specified
(numFmt - 数字格式索引和字符串表达式,如果未指定,则为 null)
isInternalDateFormat(int)
public static boolean isADateFormat(int formatIndex, java.lang.String formatString)
formatIndex
- The index of the format, eg from ExtendedFormatRecord.getFormatIndex
(formatIndex - 格式的索引,例如来自 ExtendedFormatRecord.getFormatIndex)
formatString
- The format string, eg from FormatRecord.getFormatString
(formatString - 格式字符串,例如来自 FormatRecord.getFormatString)
isInternalDateFormat(int)
public static boolean isInternalDateFormat(int format)
isADateFormat(int, java.lang.String)
public static boolean isCellDateFormatted(Cell cell)
cell
-
(细胞 -)
isADateFormat(int, String)
,
isInternalDateFormat(int)
public static boolean isCellDateFormatted(Cell cell, ConditionalFormattingEvaluator cfEvaluator)
cell
-
(细胞 -)
cfEvaluator
- if available, or null
(cfEvaluator - 如果可用,或 null)
isADateFormat(int, String)
,
isInternalDateFormat(int)
public static boolean isCellInternalDateFormatted(Cell cell)
public static boolean isValidExcelDate(double value)
value
- the double value
(value - 双精度值)
protected static int absoluteDay(java.util.Calendar cal, boolean use1904windowing)
cal
- the Calendar
(cal - 日历)
java.lang.IllegalArgumentException
- if date is invalid
(java.lang.IllegalArgumentException - 如果日期无效)
protected static int absoluteDay(java.time.LocalDateTime date, boolean use1904windowing)
date
- the Date
(日期 - 日期)
java.lang.IllegalArgumentException
- if date is invalid
(java.lang.IllegalArgumentException - 如果日期无效)
public 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 2021 The Apache Software Foundation or its licensors, as applicable.