public class DateUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
APRIL |
static int |
AUGUST |
static int |
DECEMBER |
static int |
FEBRUARY |
static int |
FRIDAY |
static int |
JANUARY |
static int |
JULY |
static int |
JUNE |
static int |
MARCH |
static int |
MAY |
static int |
MONDAY |
static int |
NOVEMBER |
static int |
OCTOBER |
static int |
SATURDAY |
static int |
SEPTEMBER |
static int |
SUNDAY |
static int |
THURSDAY |
static int |
TUESDAY |
static int |
WEDNESDAY |
| Modifier and Type | Method and Description |
|---|---|
static Date |
BuildDate(long times)
Allocates a Date object and initializes it to represent the specified
number of milliseconds since the standard base time known as "the epoch",
namely January 1, 1970, 00:00:00 GMT.
|
static Date |
formatToStartOfDay(Date date)
Returns the beginning of the given day.
|
static Date |
getCurrentDate()
Return current system date.
|
static String |
getDateFormat(Date date,
String pattern)
Format date by given pattern.
|
static String |
getDateFormat(String date,
String datePattern,
String formatPattern)
Format date from given date string and date pattern by format pattern.
|
static Date |
getDateFromString(String dateString)
The date format pattern is "yyyy-MM-dd HH:mm:ss", so you must put data
like this: '2012-12-21 00:00:00'
|
static Date |
getDateFromString(String dateString,
String pattern)
Get data from data string using the given pattern and the default date
format symbols for the default locale.
|
static Date |
getDateOfDaysBack(int daysBack,
Date date)
Get specify days back from given date.
|
static Date |
getDateOfHoursBack(int hoursBack,
Date date)
Get specify hours back form given date.
|
static Date |
getDateOfMinutesBack(int minutesBack,
Date date)
Get specify minutes back form given date.
|
static Date |
getDateOfMonthsBack(int monthsBack,
Date date)
Get specify months back from given date.
|
static Date |
getDateOfSecondsBack(int secondsBack,
Date date)
Get specify seconds back form given date.
|
static Date |
getDateOfWeeksBack(int weeksBack,
Date date)
Get specify weeks back from given date.
|
static Date |
getDateOfYearsBack(int yearsBack,
Date date)
Get specify years back from given date.
|
static int |
getDayOfMonth(Date date)
Get the day of the month by given date.
|
static int |
getDayOfWeek(Date date)
Get the day of the week by given date.
|
static int |
getDayOfYear(Date date)
Get the day number within the year by given date.
|
static int |
getHourOfDay(Date date)
Get the hour of the day by given date.
|
static int |
getMinuteOfHour(Date date)
Get the minute within the hour by given date.
E.g.: at 10:04:15.250 PM the MINUTE is 4. |
static int |
getMonthOfYear(Date date)
Get the month of year by given date.
|
static int |
getSecondOfMinute(Date date)
Get the second within the minute by given date.
E.g.: at 10:04:15.250 PM the SECOND is 15. |
static int |
getWeekOfMonth(Date date)
Get the week of the month by given date.
|
static int |
getWeekOfYear(Date date)
Get the week number within the year by given date.
|
static int |
getYear(Date date)
Get the year by given date.
|
static boolean |
isFirstDayOfTheMonth(Date date)
Return true when if the given date is the first day of the month; false
otherwise.
|
static boolean |
isLastDayOfTheMonth(Date date)
Return true if the given date is the last day of the month; false
otherwise.
|
static long |
subDays(Date date1,
Date date2)
Get how many days between two date.
|
static long |
subDays(String dateString1,
String dateString2)
Get how many days between two date, the date pattern is 'yyyy-MM-dd'.
|
static long |
subHours(Date date1,
Date date2)
Get how many hours between two date.
|
static long |
subMinutes(Date date1,
Date date2)
Get how many minutes between two date.
|
static long |
subMonths(Date date1,
Date date2)
Get how many months between two date.
|
static long |
subMonths(String dateString1,
String dateString2)
Get how many months between two date, the date pattern is 'yyyy-MM-dd'.
|
static long |
subSeconds(Date date1,
Date date2)
Get how many seconds between two date.
|
static long |
subYears(Date date1,
Date date2)
Get how many years between two date.
|
static long |
subYears(String dateString1,
String dateString2)
Get how many years between two date, the date pattern is 'yyyy-MM-dd'.
|
public static final int SUNDAY
public static final int MONDAY
public static final int TUESDAY
public static final int WEDNESDAY
public static final int THURSDAY
public static final int FRIDAY
public static final int SATURDAY
public static final int JANUARY
public static final int FEBRUARY
public static final int MARCH
public static final int APRIL
public static final int MAY
public static final int JUNE
public static final int JULY
public static final int AUGUST
public static final int SEPTEMBER
public static final int OCTOBER
public static final int NOVEMBER
public static final int DECEMBER
public static Date getDateFromString(String dateString)
dateString - date string to be handled.DateExceptionpublic static Date getDateFromString(String dateString, String pattern)
dateString - date string to be handled.pattern - pattern to be formated.DateExceptionpublic static String getDateFormat(Date date, String pattern)
date - date to be handled.pattern - pattern use to handle given date.public static String getDateFormat(String date, String datePattern, String formatPattern)
e.g:
date: '2012-12-21 13:14:20'
datePattern: 'yyyy-MM-dd'
formatPattern: 'yyyy-MM-dd 23:59:59'
result: "2012-12-21 23:59:59"
date - date string to be handled.datePattern - pattern to handle date string to date object.formatPattern - pattern use to format given date.DateExceptionpublic static Date getDateOfSecondsBack(int secondsBack, Date date)
secondsBack - how many second want to be back.date - date to be handled.public static Date getDateOfMinutesBack(int minutesBack, Date date)
minutesBack - how many minutes want to be back.date - date to be handled.public static Date getDateOfHoursBack(int hoursBack, Date date)
hoursBack - how many hours want to be back.date - date to be handled.public static Date getDateOfDaysBack(int daysBack, Date date)
daysBack - how many days want to be back.date - date to be handled.public static Date getDateOfWeeksBack(int weeksBack, Date date)
weeksBack - how many weeks want to be back.date - date to be handled.public static Date getDateOfMonthsBack(int monthsBack, Date date)
monthsBack - how many months want to be back.date - date to be handled.public static Date getDateOfYearsBack(int yearsBack, Date date)
yearsBack - how many years want to be back.date - date to be handled.public static int getSecondOfMinute(Date date)
date - date to be handled.public static int getMinuteOfHour(Date date)
date - date to be handled.public static int getHourOfDay(Date date)
date - date to be handled.public static int getDayOfWeek(Date date)
date - date to be handled.public static int getDayOfMonth(Date date)
date - date to be handled.public static int getDayOfYear(Date date)
date - date to be handled.public static int getWeekOfMonth(Date date)
date - date to be handled.public static int getWeekOfYear(Date date)
date - date to be handled.public static int getMonthOfYear(Date date)
date - date to be handled.public static int getYear(Date date)
date - date to be handled.public static boolean isFirstDayOfTheMonth(Date date)
date - date to be tested.public static boolean isLastDayOfTheMonth(Date date)
date - date to be tested.public static Date getCurrentDate()
public static Date BuildDate(long times)
times - number of milliseconds.public static long subSeconds(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static long subMinutes(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static long subHours(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static long subDays(String dateString1, String dateString2)
dateString1 - date string to be tested.dateString2 - date string to be tested.DateExceptionpublic static long subDays(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static long subMonths(String dateString1, String dateString2)
dateString1 - date string to be tested.dateString2 - date string to be tested.DateExceptionpublic static long subMonths(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static long subYears(String dateString1, String dateString2)
dateString1 - date string to be tested.dateString2 - date string to be tested.DateExceptionpublic static long subYears(Date date1, Date date2)
date1 - date to be tested.date2 - date to be tested.public static Date formatToStartOfDay(Date date)
date - date to be handled.DateExceptionCopyright © 2014. All rights reserved.