Package gr.zeus.util
Class DateHelper
- java.lang.Object
-
- gr.zeus.util.DateHelper
-
public final class DateHelper extends java.lang.ObjectHelper methods forjava.util.Date- Since:
- 1.05
- Author:
- Gregory Kotsaftis
-
-
Constructor Summary
Constructors Constructor Description DateHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddDaysToDate(java.util.Calendar cal, int days)Adds 'days' to a calendar taking into consideration the month, year and leap years change as well.static java.lang.StringdateToString(java.util.Date uDate, java.lang.String pattern)Converts a date to a string based on aSimpleDateFormatpattern.static intgetDayForDate(java.lang.String dateToCheck, java.lang.String pattern)Parses a string into a date.static java.lang.StringgetDayNameForDate(java.util.Date dt, boolean fullname)Gets the name of a day based on a date and current locale.static intgetMonthForDate(java.lang.String dateToCheck, java.lang.String pattern)Parses a string into a date.static intgetYearForDate(java.lang.String dateToCheck, java.lang.String pattern)Parses a string into a date.static booleanisDateValid(java.lang.String dateToCheck, java.lang.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 java.util.DateparseDate(java.lang.String myDate, java.lang.String pattern)Parses a string into a date.static voidsubDaysFromDate(java.util.Calendar cal, int days)Subtracts 'days' from a calendar taking into consideration the month, year and leap years change as well.
-
-
-
Method Detail
-
subDaysFromDate
public static void subDaysFromDate(java.util.Calendar cal, int days)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
public static void addDaysToDate(java.util.Calendar cal, int days)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
public static java.util.Date parseDate(java.lang.String myDate, java.lang.String pattern) throws java.text.ParseExceptionParses 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:
java.text.ParseException
-
dateToString
public static java.lang.String dateToString(java.util.Date uDate, java.lang.String pattern)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
public static boolean isDateValid(java.lang.String dateToCheck, java.lang.String pattern)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
public static int getYearForDate(java.lang.String dateToCheck, java.lang.String pattern)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
public static int getMonthForDate(java.lang.String dateToCheck, java.lang.String pattern)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
public static int getDayForDate(java.lang.String dateToCheck, java.lang.String pattern)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
public static java.lang.String getDayNameForDate(java.util.Date dt, boolean fullname)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.
-
-