public class DateUtils extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ISO8601_UTC_MASK |
static java.lang.String |
OOZIE_PROCESSING_TIMEZONE_DEFAULT |
static java.lang.String |
OOZIE_PROCESSING_TIMEZONE_KEY |
static java.util.TimeZone |
UTC |
| Constructor and Description |
|---|
DateUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.sql.Timestamp |
convertDateToTimestamp(java.util.Date d)
Convert java.util.Date to java.sql.Timestamp
|
static java.lang.String |
formatDate(java.util.Calendar c)
Formats a
Calendar as a string in ISO8601 format without adjusting its timezone. |
static java.lang.String |
formatDateCustom(java.util.Date d,
java.lang.String format)
Formats a
Date as a string using the specified format mask. |
static java.lang.String |
formatDateEpoch(java.util.Date d,
java.lang.Boolean millis)
Formats a
Date as a string containing the seconds (or millis) since the Unix epoch (Jan 1, 1970). |
static java.lang.String |
formatDateOozieTZ(java.util.Calendar c)
Formats a
Calendar as a string in ISO8601 format using Oozie processing timezone. |
static java.lang.String |
formatDateOozieTZ(java.util.Date d)
Formats a
Date as a string in ISO8601 format using Oozie processing timezone. |
static java.util.Calendar |
getCalendar(java.lang.String dateString)
Create a Calendar instance for UTC time zone using the specified date.
|
static java.util.Calendar |
getCalendar(java.lang.String dateString,
java.util.TimeZone tz)
Create a Calendar instance using the specified date and Time zone
|
static java.util.TimeZone |
getOozieProcessingTimeZone()
Returns Oozie processing timezone.
|
static java.lang.String |
getOozieTimeMask()
Returns Oozie processing datetime mask.
|
static java.util.TimeZone |
getTimeZone(java.lang.String tzId)
Returns the
TimeZone for the given timezone ID. |
static int |
hoursInDay(java.util.Calendar cal)
This function returns number of hour in a day when given a Calendar with appropriate TZ.
|
static boolean |
isDSTChangeDay(java.util.Calendar cal)
Determine whether a specific date is on DST change day
|
static void |
moveToEnd(java.util.Calendar cal,
TimeUnit endOfFlag)
Move the any date-time to the end of the duration.
|
static java.util.Date |
parseDateOozieTZ(java.lang.String s)
Parses a datetime in ISO8601 format in the Oozie processing timezone.
|
static java.util.Date |
parseDateUTC(java.lang.String s)
Parses a datetime in ISO8601 format in UTC timezone
|
static void |
setConf(org.apache.hadoop.conf.Configuration conf)
Configures the Datetime parsing with Oozie processing timezone.
|
static java.util.Date |
toDate(java.sql.Timestamp timestamp)
Convert java.sql.Timestamp to java.util.Date
|
public static final java.util.TimeZone UTC
public static final java.lang.String ISO8601_UTC_MASK
public static final java.lang.String OOZIE_PROCESSING_TIMEZONE_KEY
public static final java.lang.String OOZIE_PROCESSING_TIMEZONE_DEFAULT
public DateUtils()
public static void setConf(org.apache.hadoop.conf.Configuration conf)
OOZIE_PROCESSING_TIMEZONE_KEY property is read and set as the Oozie processing timezone.
Valid values for this property are UTC and GMT(+/-)####conf - Oozie server configuration.public static java.util.TimeZone getOozieProcessingTimeZone()
UTC or a GMT(+/-)####
timezone.public static java.lang.String getOozieTimeMask()
public static java.util.TimeZone getTimeZone(java.lang.String tzId)
TimeZone for the given timezone ID.tzId - timezone ID.TimeZone for the given timezone ID.public static java.util.Date parseDateUTC(java.lang.String s) throws java.text.ParseException
s - string with the datetime to parse.Date instance for the parsed date.java.text.ParseException - thrown if the given string was not an ISO8601 UTC value.public static java.util.Date parseDateOozieTZ(java.lang.String s) throws java.text.ParseException
s - string with the datetime to parse.Date instance for the parsed date.java.text.ParseException - thrown if the given string was not an ISO8601 value for the Oozie processing timezon.public static java.lang.String formatDateOozieTZ(java.util.Date d)
Date as a string in ISO8601 format using Oozie processing timezone.d - Date to format.NULL if the Date instance was
NULLpublic static java.lang.String formatDateCustom(java.util.Date d, java.lang.String format)
Date as a string using the specified format mask.
The format mask must be a SimpleDateFormat valid format mask.d - Date to format.NULL if the Date instance was NULLpublic static java.lang.String formatDateEpoch(java.util.Date d, java.lang.Boolean millis)
Date as a string containing the seconds (or millis) since the Unix epoch (Jan 1, 1970).
The format mask must be a SimpleDateFormat valid format maskd - Date to format.millis - true to include millisecondsNULL if the Date instance was NULLpublic static java.lang.String formatDateOozieTZ(java.util.Calendar c)
Calendar as a string in ISO8601 format using Oozie processing timezone.c - Calendar to format.NULL if the Calendar instance was
NULLpublic static java.lang.String formatDate(java.util.Calendar c)
Calendar as a string in ISO8601 format without adjusting its timezone. However, the mask will still
ensure that the returned date is in the Oozie processing timezone.c - Calendar to format.NULL if the Calendar instance was
NULLpublic static int hoursInDay(java.util.Calendar cal)
cal: - The date for which the number of hours is requestedpublic static boolean isDSTChangeDay(java.util.Calendar cal)
cal: - Date to know if it is DST change day. Appropriate TZ is specifiedpublic static void moveToEnd(java.util.Calendar cal, TimeUnit endOfFlag)
cal - : Date-time needs to be moved to the endendOfFlag - : day (for end of day) or month (for end of month) or emptypublic static java.util.Calendar getCalendar(java.lang.String dateString, java.util.TimeZone tz) throws java.lang.Exception
dateString - tz - : TimeZonejava.lang.Exceptionpublic static java.util.Calendar getCalendar(java.lang.String dateString) throws java.lang.Exception
dateString - java.lang.Exceptionpublic static java.util.Date toDate(java.sql.Timestamp timestamp)
timestamp - java.sql.Timestamppublic static java.sql.Timestamp convertDateToTimestamp(java.util.Date d)
d - java.util.DateCopyright © 2018 Apache Software Foundation. All Rights Reserved.