public class DateTimeUtils extends Object
Date value: a bit field with bits for the year, month, and day. Absolute day: the day number (0 means 1970-01-01).
Modifier and Type | Field and Description |
---|---|
static long |
MILLIS_PER_DAY
The number of milliseconds per day.
|
Modifier and Type | Method and Description |
---|---|
static long |
absoluteDayFromDateValue(long dateValue)
Calculate the absolute day from a date value.
|
static ValueDate |
convertDate(Date x,
Calendar calendar)
Convert the date using the specified calendar.
|
static Date |
convertDate(Value value,
Calendar calendar)
Convert the date to the specified time zone.
|
static Date |
convertDateValueToDate(long dateValue)
Convert a date value to a date, using the default timezone.
|
static Timestamp |
convertDateValueToTimestamp(long dateValue,
long nanos)
Convert a date value / time value to a timestamp, using the default
timezone.
|
static Time |
convertNanoToTime(long nanos)
Convert a time value to a time, using the default
timezone.
|
static ValueTime |
convertTime(Time x,
Calendar calendar)
Convert the time using the specified calendar.
|
static Time |
convertTime(Value value,
Calendar calendar)
Convert the time to the specified time zone.
|
static ValueTimestamp |
convertTimestamp(Timestamp x,
Calendar calendar)
Convert the timestamp using the specified calendar.
|
static Timestamp |
convertTimestamp(Value value,
Calendar calendar)
Convert the timestamp to the specified time zone.
|
static long |
convertToLocal(Date x,
Calendar target)
Convert a date to the specified time zone.
|
static long |
dateValue(long year,
int month,
int day)
Get the date value from a given date.
|
static long |
dateValueFromAbsoluteDay(long absoluteDay)
Calculate the date value from an absolute day.
|
static long |
dateValueFromDate(long ms)
Calculate the date value (in the default timezone) from a given time in
milliseconds in UTC.
|
static int |
dayFromDateValue(long x)
Get the day of month from a date value.
|
static String |
formatDateTime(Date date,
String format,
String locale,
String timeZone)
Formats a date using a format string.
|
static int |
getDatePart(Date d,
int field)
Get the specified field of a date, however with years normalized to
positive or negative, and month starting with 1.
|
static int |
getIsoDayOfWeek(Date date)
Return the day of week according to the ISO 8601 specification.
|
static int |
getIsoWeek(Date date)
Returns the week of the year according to the ISO 8601 specification.
|
static int |
getIsoYear(Date date)
Returns the year according to the ISO week definition.
|
static long |
getMillis(TimeZone tz,
int year,
int month,
int day,
int hour,
int minute,
int second,
int millis)
Calculate the milliseconds since 1970-01-01 (UTC) for the given date and
time (in the specified timezone).
|
static long |
getTimeLocalWithoutDst(Date d)
Get the number of milliseconds since 1970-01-01 in the local timezone, but
without daylight saving time into account.
|
static long |
getTimeUTCWithoutDst(long millis)
Convert the number of milliseconds since 1970-01-01 in the local timezone
to UTC, but without daylight saving time into account.
|
static boolean |
isValidDate(int year,
int month,
int day)
Verify if the specified date is valid.
|
static int |
monthFromDateValue(long x)
Get the month from a date value.
|
static long |
nanosFromDate(long ms)
Calculate the nanoseconds since midnight (in the default timezone) from a
given time in milliseconds in UTC.
|
static ValueTimestamp |
normalizeTimestamp(long absoluteDay,
long nanos)
Calculate the normalized timestamp.
|
static Date |
parseDateTime(String date,
String format,
String locale,
String timeZone)
Parses a date using a format string.
|
static long |
parseDateValue(String s,
int start,
int end)
Parse a date string.
|
static long |
parseTimeNanos(String s,
int start,
int end,
boolean timeOfDay)
Parse a time string.
|
static void |
resetCalendar()
Reset the calendar, for example after changing the default timezone.
|
static int |
yearFromDateValue(long x)
Get the year from a date value.
|
public static final long MILLIS_PER_DAY
public static void resetCalendar()
public static Date convertDate(Value value, Calendar calendar)
value
- the date (might be ValueNull)calendar
- the calendarpublic static Time convertTime(Value value, Calendar calendar)
value
- the time (might be ValueNull)calendar
- the calendarpublic static Timestamp convertTimestamp(Value value, Calendar calendar)
value
- the timestamp (might be ValueNull)calendar
- the calendarpublic static ValueDate convertDate(Date x, Calendar calendar)
x
- the datecalendar
- the calendarpublic static ValueTime convertTime(Time x, Calendar calendar)
x
- the timecalendar
- the calendarpublic static long convertToLocal(Date x, Calendar target)
x
- the date to converttarget
- the calendar with the target timezonepublic static ValueTimestamp convertTimestamp(Timestamp x, Calendar calendar)
x
- the timecalendar
- the calendarpublic static long parseDateValue(String s, int start, int end)
s
- the string to parsestart
- the parse index startend
- the parse index endIllegalArgumentException
- if there is a problempublic static long parseTimeNanos(String s, int start, int end, boolean timeOfDay)
s
- the string to parsestart
- the parse index startend
- the parse index endtimeOfDay
- whether the result need to be within 0 (inclusive) and 1
day (exclusive)IllegalArgumentException
- if there is a problempublic static long getMillis(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int millis)
tz
- the timezone of the parametersyear
- the absolute year (positive or negative)month
- the month (1-12)day
- the day (1-31)hour
- the hour (0-23)minute
- the minutes (0-59)second
- the number of seconds (0-59)millis
- the number of millisecondspublic static int getDatePart(Date d, int field)
d
- the datefield
- the field typepublic static long getTimeLocalWithoutDst(Date d)
d
- the datepublic static long getTimeUTCWithoutDst(long millis)
millis
- the number of milliseconds in the local timezonepublic static int getIsoDayOfWeek(Date date)
date
- the date object which day of week should be calculatedpublic static int getIsoWeek(Date date)
date
- the date object which week of year should be calculatedpublic static int getIsoYear(Date date)
date
- the date object which year should be calculatedpublic static String formatDateTime(Date date, String format, String locale, String timeZone)
date
- the date to formatformat
- the format stringlocale
- the localetimeZone
- the timezonepublic static Date parseDateTime(String date, String format, String locale, String timeZone)
date
- the date to parseformat
- the parsing formatlocale
- the localetimeZone
- the timeZonepublic static boolean isValidDate(int year, int month, int day)
year
- the yearmonth
- the month (January is 1)day
- the day (1 is the first of the month)public static Date convertDateValueToDate(long dateValue)
dateValue
- the date valuepublic static Timestamp convertDateValueToTimestamp(long dateValue, long nanos)
dateValue
- the date valuenanos
- the nanoseconds since midnightpublic static Time convertNanoToTime(long nanos)
nanos
- the nanoseconds since midnightpublic static int yearFromDateValue(long x)
x
- the date valuepublic static int monthFromDateValue(long x)
x
- the date valuepublic static int dayFromDateValue(long x)
x
- the date valuepublic static long dateValue(long year, int month, int day)
year
- the yearmonth
- the month (1..12)day
- the day (1..31)public static long dateValueFromDate(long ms)
ms
- the millisecondspublic static long nanosFromDate(long ms)
ms
- the millisecondspublic static ValueTimestamp normalizeTimestamp(long absoluteDay, long nanos)
absoluteDay
- the absolute daynanos
- the nanoseconds (may be negative or larger than one day)public static long absoluteDayFromDateValue(long dateValue)
dateValue
- the date valuepublic static long dateValueFromAbsoluteDay(long absoluteDay)
absoluteDay
- the absolute dayCopyright © 2012 JBoss by Red Hat. All Rights Reserved.