Package com.attivio.util
Class DateUtils
- java.lang.Object
-
- com.attivio.util.DateUtils
-
public class DateUtils extends java.lang.ObjectContains utilities to format and parse dates.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTIVIO_DATE_FORMATThe format to for indexed Dates in Attiviostatic java.util.TimeZoneGMTTime Zone for GMTstatic java.lang.StringISO_8601_DATE_FORMATThe ISO-8601 date format: yyyy-MM-dd'T'HH:mm:ss.static java.lang.StringISO_8601_DATE_FORMAT_DAY_ONLYThe ISO-8601 date format for days only: yyyy-MM-ddstatic java.lang.StringISO_8601_DATE_FORMAT_NO_TThe ISO-8601 date format with no 'T': yyyy-MM-dd HH:mm:ss.static java.lang.StringISO_8601_DATE_FORMAT_WITH_MILLISThe ISO-8601 date format including ms: yyyy-MM-dd'T'HH:mm:ss.static java.util.TimeZoneLOCALThe local time zonestatic java.util.TimeZoneUTCTime Zone for UTCstatic java.lang.StringXML_GREGORIANThe Gregorian date format: yyyy-MM-dd'T'HH:mm:ss.SSSZ.static java.lang.StringXML_GREGORIAN_NO_MILLISThe Gregorian date format: yyyy-MM-dd'T'HH:mm:ssZ.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDateUtils()The default constructor (hidden).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Dateceil(TimeResolution units, java.util.Date value)Roundvalueup to the nextunits.static java.lang.StringformatDate(java.util.Date d)Formats a date according to ISO_8601_DATE_FORMAT format.static java.lang.StringformatDate(java.util.Date d, java.lang.String format, java.lang.String timeZone)Formats a date according to a specified format.static java.lang.StringformatDate(java.util.Date d, java.lang.String format, java.util.TimeZone timeZone)Formats a date according to a specified format.static java.lang.StringformatDate(java.util.Date d, java.util.TimeZone timezone)Formats a date according to ISO_8601_DATE_FORMAT format.static java.lang.StringformatDuration(long time)Formats a duration ( difference between 2 times) such that only the 2 most significant time units are included.static java.util.TimeZonegetTimeZone(java.lang.String tzString)Converts the string passed intzStringto ajava.util.TimeZonestatic java.util.DateparseDate(java.lang.String s)Parses a date in ISO_8601_DATE_FORMAT format.static java.util.DateparseDate(java.lang.String dateStr, java.lang.String format, java.util.TimeZone timeZone)Parses a date in the specified format format.static java.util.DateparseDate(java.lang.String s, java.util.TimeZone timeZone)Parse a date in ISO_8601_DATE_FORMAT in the specified time zone.static java.lang.StringtimeDifference(long start, long stop)Returns the time broken down by hour, minute, second.static java.util.CalendartoCalendar(java.util.Date date)Convert a Date to a Calendar.static java.util.CalendartoCalendar(java.util.Date date, java.util.TimeZone zone)Convert a Date to a Calendar using a time zone.static java.util.DatetoDate(java.lang.Object o)Converts an arbitrary object into a Date.static java.util.DatetoDate(java.lang.Object o, java.lang.String formatString)Converts an arbitrary object into a Date based on a format string.static java.util.DatetoDate(java.lang.Object o, java.lang.String formatString, java.util.TimeZone defaultTimezone)Converts an arbitrary object into a Date based on a format string and timezone default.
-
-
-
Field Detail
-
ISO_8601_DATE_FORMAT
public static final java.lang.String ISO_8601_DATE_FORMAT
The ISO-8601 date format: yyyy-MM-dd'T'HH:mm:ss.- See Also:
- Constant Field Values
-
ISO_8601_DATE_FORMAT_WITH_MILLIS
public static final java.lang.String ISO_8601_DATE_FORMAT_WITH_MILLIS
The ISO-8601 date format including ms: yyyy-MM-dd'T'HH:mm:ss.- See Also:
- Constant Field Values
-
ISO_8601_DATE_FORMAT_DAY_ONLY
public static final java.lang.String ISO_8601_DATE_FORMAT_DAY_ONLY
The ISO-8601 date format for days only: yyyy-MM-dd- See Also:
- Constant Field Values
-
ISO_8601_DATE_FORMAT_NO_T
public static final java.lang.String ISO_8601_DATE_FORMAT_NO_T
The ISO-8601 date format with no 'T': yyyy-MM-dd HH:mm:ss.- See Also:
- Constant Field Values
-
XML_GREGORIAN_NO_MILLIS
public static final java.lang.String XML_GREGORIAN_NO_MILLIS
The Gregorian date format: yyyy-MM-dd'T'HH:mm:ssZ.- See Also:
- Constant Field Values
-
XML_GREGORIAN
public static final java.lang.String XML_GREGORIAN
The Gregorian date format: yyyy-MM-dd'T'HH:mm:ss.SSSZ.- See Also:
- Constant Field Values
-
ATTIVIO_DATE_FORMAT
public static final java.lang.String ATTIVIO_DATE_FORMAT
The format to for indexed Dates in Attivio- See Also:
- Constant Field Values
-
UTC
public static final java.util.TimeZone UTC
Time Zone for UTC
-
GMT
public static final java.util.TimeZone GMT
Time Zone for GMT
-
LOCAL
public static final java.util.TimeZone LOCAL
The local time zone
-
-
Method Detail
-
toCalendar
public static java.util.Calendar toCalendar(java.util.Date date)
Convert a Date to a Calendar.
-
toCalendar
public static java.util.Calendar toCalendar(java.util.Date date, java.util.TimeZone zone)Convert a Date to a Calendar using a time zone.
-
formatDate
public static java.lang.String formatDate(java.util.Date d, java.lang.String format, java.lang.String timeZone)Formats a date according to a specified format.- Parameters:
d- Date to formatformat- format stringtimeZone- the name of the TimeZone to use for formatting- Returns:
- String representation of Date according to format
-
formatDate
public static java.lang.String formatDate(java.util.Date d, java.lang.String format, java.util.TimeZone timeZone)Formats a date according to a specified format.- Parameters:
d- Date to formatformat- format stringtimeZone- the TimeZone to use for formatting- Returns:
- String representation of Date according to format
-
parseDate
public static java.util.Date parseDate(java.lang.String s)
Parses a date in ISO_8601_DATE_FORMAT format.- Parameters:
s- Date string to parse in ISO_8601_DATE_FORMAT format- Returns:
- Date object
- See Also:
AttivioDateFormat.parse(String)
-
parseDate
public static java.util.Date parseDate(java.lang.String s, java.util.TimeZone timeZone)Parse a date in ISO_8601_DATE_FORMAT in the specified time zone.
-
parseDate
public static java.util.Date parseDate(java.lang.String dateStr, java.lang.String format, java.util.TimeZone timeZone) throws java.text.ParseExceptionParses a date in the specified format format.- Parameters:
dateStr- Date string to parseformat- format to parse Date astimeZone- the timezone to parse dateStr as- Returns:
- Date object representation of String
- Throws:
java.text.ParseException- if the date is not in the expected format
-
formatDate
public static java.lang.String formatDate(java.util.Date d)
Formats a date according to ISO_8601_DATE_FORMAT format.- Parameters:
d- Date to format- Returns:
- String representation of Date according to ISO_8601_DATE_FORMAT
-
formatDate
public static java.lang.String formatDate(java.util.Date d, java.util.TimeZone timezone)Formats a date according to ISO_8601_DATE_FORMAT format.- Parameters:
d- Date to formattimezone- timezone to format to- Returns:
- String representation of Date according to ISO_8601_DATE_FORMAT
-
formatDuration
public static java.lang.String formatDuration(long time)
Formats a duration ( difference between 2 times) such that only the 2 most significant time units are included. The time units displayed can be days, hours, minutes, and/or seconds.For instance: 2d, 14h 2d, 35m 10h, 45m 45m, 30s 60s
- Parameters:
time- duration. (in milliseconds)- Returns:
- the duration as a human readable string
-
toDate
public static java.util.Date toDate(java.lang.Object o, java.lang.String formatString)Converts an arbitrary object into a Date based on a format string.Numbers are treated as seconds since epoch. String are treated as ISO-8601 formated date.
- Parameters:
o- the object to convertformatString- the format- Returns:
- the date
-
toDate
public static java.util.Date toDate(java.lang.Object o, java.lang.String formatString, java.util.TimeZone defaultTimezone)Converts an arbitrary object into a Date based on a format string and timezone default.Numbers are treated as seconds since epoch. String are treated as ISO-8601 formated date.
- Parameters:
o- the object to convertformatString- the formatdefaultTimezone- the fallback timezone in case the format specified doesn't contain a timezone- Returns:
- the date
-
toDate
public static java.util.Date toDate(java.lang.Object o)
Converts an arbitrary object into a Date.Numbers are treated as seconds since epoch. String are treated as ISO-8601 formated date.
- Parameters:
o- the object- Returns:
- the date
-
getTimeZone
public static java.util.TimeZone getTimeZone(java.lang.String tzString)
Converts the string passed intzStringto ajava.util.TimeZone- Parameters:
tzString- the timezone string- Returns:
- A
TimeZoneobject or null iftzStringis not a valid/known timezone
-
ceil
public static final java.util.Date ceil(TimeResolution units, java.util.Date value)
Roundvalueup to the nextunits.
-
timeDifference
public static java.lang.String timeDifference(long start, long stop)Returns the time broken down by hour, minute, second.
-
-