Package org.apache.ofbiz.base.util
Class UtilDateTime
- java.lang.Object
-
- org.apache.ofbiz.base.util.UtilDateTime
-
public final class UtilDateTime extends java.lang.Object
Utility class for handling java.util.Date, the java.sql data/time classes and related
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.sql.Timestamp
addDaysToTimestamp(java.sql.Timestamp start, int days)
static java.sql.Timestamp
addDaysToTimestamp(java.sql.Timestamp start, java.lang.Double days)
static java.sql.Timestamp
adjustTimestamp(java.sql.Timestamp stamp, int adjType, int adjQuantity, java.util.TimeZone timeZone, java.util.Locale locale)
Perform date/time arithmetic on a Timestamp.static java.sql.Timestamp
adjustTimestamp(java.sql.Timestamp stamp, java.lang.Integer adjType, java.lang.Integer adjQuantity)
static java.util.List<java.util.TimeZone>
availableTimeZones()
Returns a List of available TimeZone objects.static int
dayNumber(java.sql.Timestamp stamp)
returns a day number in a week for a Timestamp inputstatic java.lang.String
formatInterval(double interval, int count, java.util.Locale locale)
static java.lang.String
formatInterval(double interval, java.util.Locale locale)
static java.lang.String
formatInterval(long interval, int count, java.util.Locale locale)
static java.lang.String
formatInterval(long interval, java.util.Locale locale)
static java.lang.String
formatInterval(java.sql.Timestamp from, java.sql.Timestamp thru, int count, java.util.Locale locale)
static java.lang.String
formatInterval(java.sql.Timestamp from, java.sql.Timestamp thru, java.util.Locale locale)
static java.lang.String
formatInterval(java.util.Date from, java.util.Date thru, int count, java.util.Locale locale)
static java.lang.String
formatInterval(java.util.Date from, java.util.Date thru, java.util.Locale locale)
static com.ibm.icu.util.Calendar
getCalendarInstance(java.util.TimeZone timeZone, java.util.Locale locale)
static java.lang.String
getDateFormat()
static java.lang.String
getDateTimeFormat()
static java.sql.Timestamp
getDayEnd(java.sql.Timestamp stamp)
static java.sql.Timestamp
getDayEnd(java.sql.Timestamp stamp, java.lang.Long daysLater)
static java.sql.Timestamp
getDayEnd(java.sql.Timestamp stamp, java.lang.Long daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getDayEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.util.List<java.lang.String>
getDayNames(java.util.Locale locale)
Returns a List of day name Strings - suitable for calendar headings.static int
getDayOfMonth(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static int
getDayOfWeek(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static int
getDayOfYear(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getDayStart(java.sql.Timestamp stamp)
static java.sql.Timestamp
getDayStart(java.sql.Timestamp stamp, int daysLater)
static java.sql.Timestamp
getDayStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getDayStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.util.Date
getEarliestDate()
static int
getHour(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static double
getInterval(java.sql.Timestamp from, java.sql.Timestamp thru)
static double
getInterval(java.util.Date from, java.util.Date thru)
static int
getIntervalInDays(java.sql.Timestamp from, java.sql.Timestamp thru)
static java.util.Date
getLatestDate()
static int
getMinute(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static int
getMonth(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getMonthEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.util.List<java.lang.String>
getMonthNames(java.util.Locale locale)
Returns a List of month name Strings - suitable for calendar headings.static java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp)
Return the date for the first day of the monthstatic java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp, int daysLater)
static java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp, int daysLater, int monthsLater)
static java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getMonthStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getNextDayStart(java.sql.Timestamp stamp)
static int
getSecond(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.lang.String
getTimeFormat()
static java.sql.Timestamp
getTimestamp(long time)
Convert a millisecond value to a Timestamp.static java.sql.Timestamp
getTimestamp(java.lang.String milliSecs)
Convert a millisecond value to a Timestamp.static int
getWeek(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getWeekEnd(java.sql.Timestamp stamp)
static java.sql.Timestamp
getWeekEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp)
Return the date for the first day of the weekstatic java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp, int daysLater)
static java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp, int daysLater, int weeksLater)
static java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp, int daysLater, int weeksLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getWeekStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static int
getYear(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp)
Return the date for the first day of the yearstatic java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater, int yearsLater)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, int yearsLater)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, int yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater, int yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, java.lang.Number daysLater, java.lang.Number monthsLater, java.lang.Number yearsLater)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, java.lang.Number daysLater, java.lang.Number monthsLater, java.lang.Number yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
getYearStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
static java.sql.Timestamp
monthBegin()
Makes a Timestamp for the beginning of the monthstatic java.lang.String
nowAsString()
Returns currentTimeMillis as Stringstatic java.util.Date
nowDate()
Return a Date for right nowstatic java.lang.String
nowDateString()
Return a string formatted as yyyyMMddHHmmssstatic java.lang.String
nowDateString(java.lang.String format)
Return a string formatted as formatstatic java.sql.Timestamp
nowTimestamp()
Return a Timestamp for right nowstatic java.sql.Timestamp
stringToTimeStamp(java.lang.String dateTimeString, java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale)
Localized String to Timestamp conversion.static java.sql.Timestamp
stringToTimeStamp(java.lang.String dateTimeString, java.util.TimeZone tz, java.util.Locale locale)
Localized String to Timestamp conversion.static java.lang.String
timeStampToString(java.sql.Timestamp stamp, java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale)
Localized Timestamp to String conversion.static java.lang.String
timeStampToString(java.sql.Timestamp stamp, java.util.TimeZone tz, java.util.Locale locale)
Localized Timestamp to String conversion.static com.ibm.icu.util.Calendar
toCalendar(java.sql.Timestamp stamp)
static com.ibm.icu.util.Calendar
toCalendar(java.util.Date date, java.util.TimeZone timeZone, java.util.Locale locale)
Returns a Calendar object initialized to the specified date/time, time zone, and locale.static java.util.Date
toDate(int month, int day, int year, int hour, int minute, int second)
Makes a Date from separate ints for month, day, year, hour, minute, and second.static java.util.Date
toDate(java.lang.String dateTime)
Converts a date and time String into a Datestatic java.util.Date
toDate(java.lang.String date, java.lang.String time)
Converts a date String and a time String into a Datestatic java.util.Date
toDate(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr, java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a Date from separate Strings for month, day, year, hour, minute, and second.static java.text.DateFormat
toDateFormat(java.lang.String dateFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.static java.lang.String
toDateString(java.util.Date date)
Makes a date String in the format MM/DD/YYYY from a Datestatic java.lang.String
toDateString(java.util.Date date, java.lang.String format)
Makes a date String in the given from a Datestatic java.text.DateFormat
toDateTimeFormat(java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.static java.lang.String
toDateTimeString(java.util.Date date)
Makes a combined data and time string in the format "MM/DD/YYYY HH:MM:SS" from a Date.static java.lang.String
toGmtTimestampString(java.sql.Timestamp timestamp)
static java.sql.Date
toSqlDate(int month, int day, int year)
Makes a java.sql.Date from separate ints for month, day, yearstatic java.sql.Date
toSqlDate(java.lang.String date)
Converts a date String into a java.sql.Datestatic java.sql.Date
toSqlDate(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr)
Makes a java.sql.Date from separate Strings for month, day, yearstatic java.sql.Time
toSqlTime(int hour, int minute, int second)
Makes a java.sql.Time from separate ints for hour, minute, and second.static java.sql.Time
toSqlTime(java.lang.String time)
Converts a time String into a java.sql.Timestatic java.sql.Time
toSqlTime(java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a java.sql.Time from separate Strings for hour, minute, and second.static java.text.DateFormat
toTimeFormat(java.lang.String timeFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.static java.sql.Timestamp
toTimestamp(int month, int day, int year, int hour, int minute, int second)
Makes a Timestamp from separate ints for month, day, year, hour, minute, and second.static java.sql.Timestamp
toTimestamp(java.lang.String dateTime)
Converts a date and time String into a Timestampstatic java.sql.Timestamp
toTimestamp(java.lang.String date, java.lang.String time)
Converts a date String and a time String into a Timestampstatic java.sql.Timestamp
toTimestamp(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr, java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a Timestamp from separate Strings for month, day, year, hour, minute, and second.static java.sql.Timestamp
toTimestamp(java.util.Date date)
static java.lang.String
toTimeString(int hour, int minute, int second)
Makes a time String in the format HH:MM:SS from a separate ints for hour, minute, and second.static java.lang.String
toTimeString(java.util.Date date)
Makes a time String in the format HH:MM:SS from a Date.static java.util.TimeZone
toTimeZone(int gmtOffset)
Returns a TimeZone object based upon an hour offset from GMT.static java.util.TimeZone
toTimeZone(java.lang.String tzId)
Returns a TimeZone object based upon a time zone ID.static java.util.Date
unmodifiableDate(java.util.Date date)
Returns a copy ofdate
that cannot be modified.static int
weekNumber(java.sql.Timestamp input)
returns a week number in a year for a Timestamp inputstatic int
weekNumber(java.sql.Timestamp input, int startOfWeek)
static int
weekNumber(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
-
-
Method Detail
-
getInterval
public static double getInterval(java.util.Date from, java.util.Date thru)
-
getIntervalInDays
public static int getIntervalInDays(java.sql.Timestamp from, java.sql.Timestamp thru)
-
addDaysToTimestamp
public static java.sql.Timestamp addDaysToTimestamp(java.sql.Timestamp start, int days)
-
addDaysToTimestamp
public static java.sql.Timestamp addDaysToTimestamp(java.sql.Timestamp start, java.lang.Double days)
-
getInterval
public static double getInterval(java.sql.Timestamp from, java.sql.Timestamp thru)
-
formatInterval
public static java.lang.String formatInterval(java.util.Date from, java.util.Date thru, int count, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(java.util.Date from, java.util.Date thru, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(java.sql.Timestamp from, java.sql.Timestamp thru, int count, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(java.sql.Timestamp from, java.sql.Timestamp thru, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(long interval, int count, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(long interval, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(double interval, java.util.Locale locale)
-
formatInterval
public static java.lang.String formatInterval(double interval, int count, java.util.Locale locale)
-
nowTimestamp
public static java.sql.Timestamp nowTimestamp()
Return a Timestamp for right now- Returns:
- Timestamp for right now
-
getTimestamp
public static java.sql.Timestamp getTimestamp(long time)
Convert a millisecond value to a Timestamp.- Parameters:
time
- millsecond value- Returns:
- Timestamp
-
getTimestamp
public static java.sql.Timestamp getTimestamp(java.lang.String milliSecs) throws java.lang.NumberFormatException
Convert a millisecond value to a Timestamp.- Parameters:
milliSecs
- millsecond value- Returns:
- Timestamp
- Throws:
java.lang.NumberFormatException
-
nowAsString
public static java.lang.String nowAsString()
Returns currentTimeMillis as String- Returns:
- String(currentTimeMillis)
-
nowDateString
public static java.lang.String nowDateString()
Return a string formatted as yyyyMMddHHmmss- Returns:
- String formatted for right now
-
nowDateString
public static java.lang.String nowDateString(java.lang.String format)
Return a string formatted as format- Returns:
- String formatted for right now
-
nowDate
public static java.util.Date nowDate()
Return a Date for right now- Returns:
- Date for right now
-
getDayStart
public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp)
-
getDayStart
public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, int daysLater)
-
getNextDayStart
public static java.sql.Timestamp getNextDayStart(java.sql.Timestamp stamp)
-
getDayEnd
public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp)
-
getDayEnd
public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp, java.lang.Long daysLater)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp)
Return the date for the first day of the year- Parameters:
stamp
-- Returns:
- java.sql.Timestamp
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, int yearsLater)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, int yearsLater)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, java.lang.Number daysLater, java.lang.Number monthsLater, java.lang.Number yearsLater)
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp)
Return the date for the first day of the month- Parameters:
stamp
-- Returns:
- java.sql.Timestamp
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, int daysLater)
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, int daysLater, int monthsLater)
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp)
Return the date for the first day of the week- Parameters:
stamp
-- Returns:
- java.sql.Timestamp
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, int daysLater)
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, int daysLater, int weeksLater)
-
getWeekEnd
public static java.sql.Timestamp getWeekEnd(java.sql.Timestamp stamp)
-
toCalendar
public static com.ibm.icu.util.Calendar toCalendar(java.sql.Timestamp stamp)
-
toSqlDate
public static java.sql.Date toSqlDate(java.lang.String date)
Converts a date String into a java.sql.Date- Parameters:
date
- The date String: MM/DD/YYYY- Returns:
- A java.sql.Date made from the date String
-
toSqlDate
public static java.sql.Date toSqlDate(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr)
Makes a java.sql.Date from separate Strings for month, day, year- Parameters:
monthStr
- The month StringdayStr
- The day StringyearStr
- The year String- Returns:
- A java.sql.Date made from separate Strings for month, day, year
-
toSqlDate
public static java.sql.Date toSqlDate(int month, int day, int year)
Makes a java.sql.Date from separate ints for month, day, year- Parameters:
month
- The month intday
- The day intyear
- The year int- Returns:
- A java.sql.Date made from separate ints for month, day, year
-
toSqlTime
public static java.sql.Time toSqlTime(java.lang.String time)
Converts a time String into a java.sql.Time- Parameters:
time
- The time String: either HH:MM or HH:MM:SS- Returns:
- A java.sql.Time made from the time String
-
toSqlTime
public static java.sql.Time toSqlTime(java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a java.sql.Time from separate Strings for hour, minute, and second.- Parameters:
hourStr
- The hour StringminuteStr
- The minute StringsecondStr
- The second String- Returns:
- A java.sql.Time made from separate Strings for hour, minute, and second.
-
toSqlTime
public static java.sql.Time toSqlTime(int hour, int minute, int second)
Makes a java.sql.Time from separate ints for hour, minute, and second.- Parameters:
hour
- The hour intminute
- The minute intsecond
- The second int- Returns:
- A java.sql.Time made from separate ints for hour, minute, and second.
-
toTimestamp
public static java.sql.Timestamp toTimestamp(java.lang.String dateTime)
Converts a date and time String into a Timestamp- Parameters:
dateTime
- A combined data and time string in the format "MM/DD/YYYY HH:MM:SS", the seconds are optional- Returns:
- The corresponding Timestamp
-
toTimestamp
public static java.sql.Timestamp toTimestamp(java.lang.String date, java.lang.String time)
Converts a date String and a time String into a Timestamp- Parameters:
date
- The date String: MM/DD/YYYYtime
- The time String: either HH:MM or HH:MM:SS- Returns:
- A Timestamp made from the date and time Strings
-
toTimestamp
public static java.sql.Timestamp toTimestamp(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr, java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a Timestamp from separate Strings for month, day, year, hour, minute, and second.- Parameters:
monthStr
- The month StringdayStr
- The day StringyearStr
- The year StringhourStr
- The hour StringminuteStr
- The minute StringsecondStr
- The second String- Returns:
- A Timestamp made from separate Strings for month, day, year, hour, minute, and second.
-
toTimestamp
public static java.sql.Timestamp toTimestamp(int month, int day, int year, int hour, int minute, int second)
Makes a Timestamp from separate ints for month, day, year, hour, minute, and second.- Parameters:
month
- The month intday
- The day intyear
- The year inthour
- The hour intminute
- The minute intsecond
- The second int- Returns:
- A Timestamp made from separate ints for month, day, year, hour, minute, and second.
-
toTimestamp
public static java.sql.Timestamp toTimestamp(java.util.Date date)
-
toDate
public static java.util.Date toDate(java.lang.String dateTime)
Converts a date and time String into a Date- Parameters:
dateTime
- A combined data and time string in the format "MM/DD/YYYY HH:MM:SS", the seconds are optional- Returns:
- The corresponding Date
-
toDate
public static java.util.Date toDate(java.lang.String date, java.lang.String time)
Converts a date String and a time String into a Date- Parameters:
date
- The date String: MM/DD/YYYYtime
- The time String: either HH:MM or HH:MM:SS- Returns:
- A Date made from the date and time Strings
-
toDate
public static java.util.Date toDate(java.lang.String monthStr, java.lang.String dayStr, java.lang.String yearStr, java.lang.String hourStr, java.lang.String minuteStr, java.lang.String secondStr)
Makes a Date from separate Strings for month, day, year, hour, minute, and second.- Parameters:
monthStr
- The month StringdayStr
- The day StringyearStr
- The year StringhourStr
- The hour StringminuteStr
- The minute StringsecondStr
- The second String- Returns:
- A Date made from separate Strings for month, day, year, hour, minute, and second.
-
toDate
public static java.util.Date toDate(int month, int day, int year, int hour, int minute, int second)
Makes a Date from separate ints for month, day, year, hour, minute, and second.- Parameters:
month
- The month intday
- The day intyear
- The year inthour
- The hour intminute
- The minute intsecond
- The second int- Returns:
- A Date made from separate ints for month, day, year, hour, minute, and second.
-
toDateString
public static java.lang.String toDateString(java.util.Date date, java.lang.String format)
Makes a date String in the given from a Date- Parameters:
date
- The Date- Returns:
- A date String in the given format
-
toDateString
public static java.lang.String toDateString(java.util.Date date)
Makes a date String in the format MM/DD/YYYY from a Date- Parameters:
date
- The Date- Returns:
- A date String in the format MM/DD/YYYY
-
toTimeString
public static java.lang.String toTimeString(java.util.Date date)
Makes a time String in the format HH:MM:SS from a Date. If the seconds are 0, then the output is in HH:MM.- Parameters:
date
- The Date- Returns:
- A time String in the format HH:MM:SS or HH:MM
-
toTimeString
public static java.lang.String toTimeString(int hour, int minute, int second)
Makes a time String in the format HH:MM:SS from a separate ints for hour, minute, and second. If the seconds are 0, then the output is in HH:MM.- Parameters:
hour
- The hour intminute
- The minute intsecond
- The second int- Returns:
- A time String in the format HH:MM:SS or HH:MM
-
toDateTimeString
public static java.lang.String toDateTimeString(java.util.Date date)
Makes a combined data and time string in the format "MM/DD/YYYY HH:MM:SS" from a Date. If the seconds are 0 they are left off.- Parameters:
date
- The Date- Returns:
- A combined data and time string in the format "MM/DD/YYYY HH:MM:SS" where the seconds are left off if they are 0.
-
toGmtTimestampString
public static java.lang.String toGmtTimestampString(java.sql.Timestamp timestamp)
-
monthBegin
public static java.sql.Timestamp monthBegin()
Makes a Timestamp for the beginning of the month- Returns:
- A Timestamp of the beginning of the month
-
weekNumber
public static int weekNumber(java.sql.Timestamp input)
returns a week number in a year for a Timestamp input- Parameters:
input
- Timestamp date- Returns:
- A int containing the week number
-
dayNumber
public static int dayNumber(java.sql.Timestamp stamp)
returns a day number in a week for a Timestamp input- Parameters:
stamp
- Timestamp date- Returns:
- A int containing the day number (sunday = 1, saturday = 7)
-
weekNumber
public static int weekNumber(java.sql.Timestamp input, int startOfWeek)
-
getCalendarInstance
public static com.ibm.icu.util.Calendar getCalendarInstance(java.util.TimeZone timeZone, java.util.Locale locale)
-
toCalendar
public static com.ibm.icu.util.Calendar toCalendar(java.util.Date date, java.util.TimeZone timeZone, java.util.Locale locale)
Returns a Calendar object initialized to the specified date/time, time zone, and locale.- Parameters:
date
- date/time to usetimeZone
-locale
-- Returns:
- Calendar object
- See Also:
Calendar
-
adjustTimestamp
public static java.sql.Timestamp adjustTimestamp(java.sql.Timestamp stamp, int adjType, int adjQuantity, java.util.TimeZone timeZone, java.util.Locale locale)
Perform date/time arithmetic on a Timestamp. This is the only accurate way to perform date/time arithmetic across locales and time zones.- Parameters:
stamp
- date/time to perform arithmetic onadjType
- the adjustment type to perform. Use one of the java.util.Calendar fields.adjQuantity
- the adjustment quantity.timeZone
-locale
-- Returns:
- adjusted Timestamp
- See Also:
Calendar
-
adjustTimestamp
public static java.sql.Timestamp adjustTimestamp(java.sql.Timestamp stamp, java.lang.Integer adjType, java.lang.Integer adjQuantity)
-
getDayStart
public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayStart
public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayEnd
public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayEnd
public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp, java.lang.Long daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getWeekStart
public static java.sql.Timestamp getWeekStart(java.sql.Timestamp stamp, int daysLater, int weeksLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getWeekEnd
public static java.sql.Timestamp getWeekEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMonthStart
public static java.sql.Timestamp getMonthStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMonthEnd
public static java.sql.Timestamp getMonthEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, int yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, java.lang.Number daysLater, java.lang.Number monthsLater, java.lang.Number yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearStart
public static java.sql.Timestamp getYearStart(java.sql.Timestamp stamp, int daysLater, int monthsLater, int yearsLater, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYearEnd
public static java.sql.Timestamp getYearEnd(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
weekNumber
public static int weekNumber(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayNames
public static java.util.List<java.lang.String> getDayNames(java.util.Locale locale)
Returns a List of day name Strings - suitable for calendar headings.- Parameters:
locale
-- Returns:
- List of day name Strings
-
getMonthNames
public static java.util.List<java.lang.String> getMonthNames(java.util.Locale locale)
Returns a List of month name Strings - suitable for calendar headings.- Parameters:
locale
-- Returns:
- List of month name Strings
-
toDateFormat
public static java.text.DateFormat toDateFormat(java.lang.String dateFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.- Parameters:
dateFormat
- optional format stringtz
-locale
- can be null if dateFormat is not null- Returns:
- DateFormat object
-
toDateTimeFormat
public static java.text.DateFormat toDateTimeFormat(java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.- Parameters:
dateTimeFormat
- optional format stringtz
-locale
- can be null if dateTimeFormat is not null- Returns:
- DateFormat object
-
toTimeFormat
public static java.text.DateFormat toTimeFormat(java.lang.String timeFormat, java.util.TimeZone tz, java.util.Locale locale)
Returns an initialized DateFormat object.- Parameters:
timeFormat
- optional format stringtz
-locale
- can be null if timeFormat is not null- Returns:
- DateFormat object
-
stringToTimeStamp
public static java.sql.Timestamp stringToTimeStamp(java.lang.String dateTimeString, java.util.TimeZone tz, java.util.Locale locale) throws java.text.ParseException
Localized String to Timestamp conversion. To be used in tandem with timeStampToString().- Throws:
java.text.ParseException
-
stringToTimeStamp
public static java.sql.Timestamp stringToTimeStamp(java.lang.String dateTimeString, java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale) throws java.text.ParseException
Localized String to Timestamp conversion. To be used in tandem with timeStampToString().- Throws:
java.text.ParseException
-
timeStampToString
public static java.lang.String timeStampToString(java.sql.Timestamp stamp, java.util.TimeZone tz, java.util.Locale locale)
Localized Timestamp to String conversion. To be used in tandem with stringToTimeStamp().
-
timeStampToString
public static java.lang.String timeStampToString(java.sql.Timestamp stamp, java.lang.String dateTimeFormat, java.util.TimeZone tz, java.util.Locale locale)
Localized Timestamp to String conversion. To be used in tandem with stringToTimeStamp().
-
availableTimeZones
public static java.util.List<java.util.TimeZone> availableTimeZones()
Returns a List of available TimeZone objects.- See Also:
TimeZone
-
toTimeZone
public static java.util.TimeZone toTimeZone(java.lang.String tzId)
Returns a TimeZone object based upon a time zone ID. Method defaults to server's time zone if tzID is null or empty.- See Also:
TimeZone
-
toTimeZone
public static java.util.TimeZone toTimeZone(int gmtOffset)
Returns a TimeZone object based upon an hour offset from GMT.- See Also:
TimeZone
-
getSecond
public static int getSecond(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMinute
public static int getMinute(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getHour
public static int getHour(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayOfWeek
public static int getDayOfWeek(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayOfMonth
public static int getDayOfMonth(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getDayOfYear
public static int getDayOfYear(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getWeek
public static int getWeek(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getMonth
public static int getMonth(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getYear
public static int getYear(java.sql.Timestamp stamp, java.util.TimeZone timeZone, java.util.Locale locale)
-
getEarliestDate
public static java.util.Date getEarliestDate()
-
getLatestDate
public static java.util.Date getLatestDate()
-
unmodifiableDate
public static java.util.Date unmodifiableDate(java.util.Date date)
Returns a copy ofdate
that cannot be modified. Attempts to modify the returned date will result in anUnsupportedOperationException
.- Parameters:
date
- the date to copy- Returns:
- an immutable copy of
date
.
-
getDateFormat
public static java.lang.String getDateFormat()
-
getDateTimeFormat
public static java.lang.String getDateTimeFormat()
-
getTimeFormat
public static java.lang.String getTimeFormat()
-
-