Package gr.zeus.util
Class DateHelper
java.lang.Object
gr.zeus.util.DateHelper
Helper methods for
java.util.Date
- Since:
- 1.05
- Author:
- Gregory Kotsaftis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDaysToDate(Calendar cal, int days) Adds 'days' to a calendar taking into consideration the month, year and leap years change as well.static StringdateToString(Date uDate, String pattern) Converts a date to a string based on aSimpleDateFormatpattern.static intgetDayForDate(String dateToCheck, String pattern) Parses a string into a date.static StringgetDayNameForDate(Date dt, boolean fullname) Gets the name of a day based on a date and current locale.static intgetMonthForDate(String dateToCheck, String pattern) Parses a string into a date.static intgetYearForDate(String dateToCheck, String pattern) Parses a string into a date.static booleanisDateValid(String dateToCheck, String pattern) Checks a string to see if it contains a valid date inSimpleDateFormat.static booleanisLeapYear(int year) Leap years occur in years exactly divisible by four, except those years ending in 00 are leap years only if they are divisible by 400.static DateParses a string into a date.static voidsubDaysFromDate(Calendar cal, int days) Subtracts 'days' from a calendar taking into consideration the month, year and leap years change as well.
-
Constructor Details
-
DateHelper
public DateHelper()
-
-
Method Details
-
subDaysFromDate
Subtracts 'days' from a calendar taking into consideration the month, year and leap years change as well.- Parameters:
cal- TheCalendar.days- The number of days.
-
addDaysToDate
Adds 'days' to a calendar taking into consideration the month, year and leap years change as well.- Parameters:
cal- TheCalendar.days- The number of days.
-
isLeapYear
public static boolean isLeapYear(int year) Leap years occur in years exactly divisible by four, except those years ending in 00 are leap years only if they are divisible by 400.- Parameters:
year- The year number.- Returns:
trueif it is a leap year.
-
parseDate
Parses a string into a date. String should be inSimpleDateFormatformat. e.g.java.util.Date d = parseDate(myDate, "dd/MM/yyyy");- Parameters:
myDate- The date string.pattern- The pattern to use.- Returns:
- The
Date. - Throws:
ParseException
-
dateToString
Converts a date to a string based on aSimpleDateFormatpattern. e.g.String s = dateToString(uDate, "dd/MM/yyyy");- Parameters:
uDate- The date string.pattern- The pattern to use.- Returns:
- The string of the date or
nullon error.
-
isDateValid
Checks a string to see if it contains a valid date inSimpleDateFormat.- Parameters:
dateToCheck- The date string to check.pattern- The pattern to use.- Returns:
trueif it contains a valid date inSimpleDateFormat.
-
getYearForDate
Parses a string into a date. String should be inSimpleDateFormatformat. Returns only the year of the date or -1 on error.NOTE: only 'yyyy' is supported!
- Parameters:
dateToCheck- The date string to check.pattern- the The pattern to use.- Returns:
- The date or -1 on error.
-
getMonthForDate
Parses a string into a date. String should be inSimpleDateFormatformat. Returns only the month of the date or -1 on error.NOTE: only 'MM' is supported!
- Parameters:
dateToCheck- The date string to check.pattern- The pattern to use.- Returns:
- The date or -1 on error.
-
getDayForDate
Parses a string into a date. String should be inSimpleDateFormatformat. Returns only the day of the date or -1 on error.NOTE: only 'dd' is supported!
- Parameters:
dateToCheck- The date string to check.pattern- The pattern to use.- Returns:
- The day for the date or -1 on error.
-
getDayNameForDate
Gets the name of a day based on a date and current locale.- Parameters:
dt- The date.fullname- Fetch complete day's name or the short one.- Returns:
- A string with the name of the day.
-