java.lang.ObjectDateUtil
public class DateUtil
A class DateUtil with the following methods for dealing with dates. public static String convertDateToLongString(Date date) public static String convertDateToShortString(Date date) public static Date convertStringToDate(String dateString) public static int daysBetween(Date startDate, Date endDate) public static Date incrementDate(Date date, int noOfDays) public static boolean isLeapYear(int year) public static boolean isValidDateString(String dateString) public static Date nextDate(Date date)
Field Summary | |
---|---|
static java.text.SimpleDateFormat |
dateFormatter
|
Constructor Summary | |
---|---|
DateUtil()
|
Method Summary | |
---|---|
static java.lang.String |
convertDateToLongString(java.util.Date date)
Converts a Date object to a corresponding String in the long date pattern style "Saturday, 25 March 2023". |
static java.lang.String |
convertDateToShortString(java.util.Date date)
Converts a Date object to a corresponding String in the short date pattern style "25-03-2023". |
static java.util.Date |
convertStringToDate(java.lang.String dateString)
Converts a string in the short date pattern style "25-03-2023" to a corresponding Date object. |
static int |
daysBetween(java.util.Date startDate,
java.util.Date endDate)
Calculates the number of days between two given dates, startDate and endDate. |
static java.util.Date |
incrementDate(java.util.Date date,
int noOfDays)
Given date, a Date object, and noOfDays, an int, the method returns a Date object corresponding to noOfDays later than date. |
static boolean |
isLeapYear(int year)
Given year, an int, the method checks to see if the year is a leap year. |
static boolean |
isValidDateString(java.lang.String dateString)
Given dateString, a String, the method checks to see if string corresponds to a valid shortDatePattern. |
static java.util.Date |
nextDate(java.util.Date date)
Given date, a Date object, the method returns a Date object corresponding to the next day. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.text.SimpleDateFormat dateFormatter
Constructor Detail |
---|
public DateUtil()
Method Detail |
---|
public static java.lang.String convertDateToLongString(java.util.Date date)
date
- a Date object
public static java.lang.String convertDateToShortString(java.util.Date date)
date
- a Date object
public static java.util.Date convertStringToDate(java.lang.String dateString)
dateString
- a Date object
public static int daysBetween(java.util.Date startDate, java.util.Date endDate)
startDate
- a Date objectendDate
- a Date object
public static java.util.Date incrementDate(java.util.Date date, int noOfDays)
date
- a Date objectnoOfDays
- an int
public static boolean isLeapYear(int year)
year,
- an int
public static boolean isValidDateString(java.lang.String dateString)
dateString,
- a String
public static java.util.Date nextDate(java.util.Date date)
noOfDays
- an int