|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.assertj.core.util.Dates
public class Dates
Utility methods related to dates.
| Constructor Summary | |
|---|---|
Dates()
|
|
| Method Summary | |
|---|---|
static int |
dayOfMonthOf(Date date)
Dates Extracts the day of month of the given Date. |
static int |
dayOfWeekOf(Date date)
Extracts the day of week of the given Date, returned value follows Calendar.DAY_OF_WEEK . |
static String |
formatAsDatetime(Calendar calendar)
Formats the date of the given calendar using the ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss). Method is thread safe. |
static String |
formatAsDatetime(Date date)
Formats the given date using the ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss). Method in synchronized because SimpleDateFormat is not thread safe (sigh). |
static String |
formatAsDatetimeWithMs(Date date)
Formats the given date using the ISO 8601 date-time format with millisecond (yyyy-MM-dd'T'HH:mm:ss:SSS). Method in synchronized because SimpleDateFormat is not thread safe (sigh). |
static String |
formatTimeDifference(Date date1,
Date date2)
Utility method to display a human readable time difference. |
static int |
hourOfDayOf(Date date)
Extracts the hour of day if the given Date (24-hour clock). |
static int |
millisecondOf(Date date)
Extracts the millisecond of the given Date. |
static int |
minuteOf(Date date)
Dates Extracts the minute of the given Date. |
static int |
monthOf(Date date)
Dates Extracts the month of the given Date starting at 1 (January=1, February=2, ...). |
static DateFormat |
newIsoDateFormat()
ISO 8601 date format (yyyy-MM-dd), example : 2003-04-23 |
static DateFormat |
newIsoDateTimeFormat()
ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : 2003-04-26T13:01:02 |
static DateFormat |
newIsoDateTimeWithMsFormat()
ISO 8601 date-time format with millisecond (yyyy-MM-dd'T'HH:mm:ss.SSS), example : 2003-04-26T03:01:02.999 |
static Date |
now()
|
static Date |
parse(String dateAsString)
Utility method to parse a Date following ISO_DATE_FORMAT, returns null if the given String is null. |
static Date |
parseDatetime(String dateAsString)
Utility method to parse a Date following ISO_DATE_TIME_FORMAT, returns null if the given String is null. |
static Date |
parseDatetimeWithMs(String dateAsString)
Utility method to parse a Date following ISO_DATE_TIME_FORMAT_WITH_MS, returns null if the given String is
null. |
static int |
secondOf(Date date)
Extracts the second of the given Date. |
static long |
timeDifference(Date date1,
Date date2)
Compute the time difference between the two given dates in milliseconds, it always gives a positive result. |
static Calendar |
toCalendar(Date date)
Converts the given Date to Calendar, returns null if the given Date is null. |
static Date |
tomorrow()
|
static Date |
truncateTime(Date date)
Returns a copy of the given date without the time part (which is set to 00:00:00), for example : truncateTime(2008-12-29T23:45:12) will give 2008-12-29T00:00:00. |
static int |
yearOf(Date date)
Extracts the year of the given Date. |
static Date |
yesterday()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Dates()
| Method Detail |
|---|
public static DateFormat newIsoDateFormat()
2003-04-23
public static DateFormat newIsoDateTimeFormat()
2003-04-26T13:01:02
public static DateFormat newIsoDateTimeWithMsFormat()
2003-04-26T03:01:02.999
public static String formatAsDatetime(Date date)
date - the date to format.
public static String formatAsDatetimeWithMs(Date date)
date - the date to format.
public static String formatAsDatetime(Calendar calendar)
calendar - the calendar to format.
public static Date parse(String dateAsString)
ISO_DATE_FORMAT, returns null if the given String is null.
dateAsString - the string to parse as a Date following ISO_DATE_FORMAT
RuntimeException - encapsulating ParseException if the string can't be parsed as a Datepublic static Date parseDatetime(String dateAsString)
ISO_DATE_TIME_FORMAT, returns null if the given String is null.
Example:
Date date = parseDatetime("2003-04-26T03:01:02");
dateAsString - the string to parse as a Date following ISO_DATE_TIME_FORMAT
RuntimeException - encapsulating ParseException if the string can't be parsed as a Datepublic static Date parseDatetimeWithMs(String dateAsString)
ISO_DATE_TIME_FORMAT_WITH_MS, returns null if the given String is
null. Example:
Date date = parseDatetimeWithMs("2003-04-26T03:01:02.999");
dateAsString - the string to parse as a Date following ISO_DATE_TIME_FORMAT_WITH_MS
RuntimeException - encapsulating ParseException if the string can't be parsed as a Datepublic static Calendar toCalendar(Date date)
date - the date to convert to a Calendar.
public static int yearOf(Date date)
date - the date to extract the year from - must not be null.
NullPointerException - if given Date is nullpublic static int monthOf(Date date)
date - the date to extract the month from - must not be null.
NullPointerException - if given Date is nullpublic static int dayOfMonthOf(Date date)
date - the date to extract the day of month from - must not be null.
NullPointerException - if given Date is nullpublic static int dayOfWeekOf(Date date)
Calendar.DAY_OF_WEEK .
date - the date to extract the day of week from - must not be null.
NullPointerException - if given Date is nullpublic static int hourOfDayOf(Date date)
date - the date to extract the hour of day from - must not be null.
NullPointerException - if given Date is nullpublic static int minuteOf(Date date)
date - the date to extract the minute from - must not be null.
NullPointerException - if given Date is nullpublic static int secondOf(Date date)
date - the date to extract the second from - must not be null.
NullPointerException - if given Date is nullpublic static int millisecondOf(Date date)
date - the date to extract the millisecond from - must not be null.
NullPointerException - if given Date is null
public static long timeDifference(Date date1,
Date date2)
date1 - the first date.date1 - the second date.
IllegalArgumentException - if one a the given Date is null.public static Date truncateTime(Date date)
truncateTime(2008-12-29T23:45:12) will give 2008-12-29T00:00:00.
Returns null if the given Date is null.
date - we want to get the day part (the parameter is read only).
public static Date now()
public static Date yesterday()
public static Date tomorrow()
public static String formatTimeDifference(Date date1,
Date date2)
date1 - date2 -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||