Anyframe Core

anyframe.common.util
Class DateUtil

java.lang.Object
  extended by anyframe.common.util.DateUtil

public abstract class DateUtil
extends Object

Date Utility Class
This is used to manage Date Object.

Author:
SoYon Lim, JongHoon Kim

Method Summary
static String calendar2String(Calendar calendar)
          convert java.util.Calendar to String
static String date2String(Date date)
          convert java.util.Date to String type
static String date2String(Date date, String format)
          convert java.util.Date to String type
static boolean equals(Date date1, Date date2)
          Compares two dates for equality.
static boolean equals(Date date1, String date2)
          Compares two dates for equality.
static boolean equals(Date date1, String date2, String date2format)
          Compares two dates for equality.
static String getCurrentDay()
          get current day
static String getCurrentHour()
          get current hour
static String getCurrentTime()
          get current system time
static String getCurrentTime(String format)
          get current time with date format
static String[] getDates(String startDay, String endDay)
          find dates between startDay and endDay
static String[] getDates(String startDay, String endDay, String format)
          find dates between startDay and endDay
static int getDays(Calendar cal1, Calendar cal2)
          It returns the number of days between two Gregorian Calendar dates (e.g.
static int getDays(String date1, String date2)
          It returns the number of days between two string type dates.
static String getDefaultDatePattern()
          Return default datePattern (yyyy-MM-dd)
static String getEndDate(String startDay, int intervalDays)
          getting end date intervalDays <= 40
static int getMinutes(Calendar cal1, Calendar cal2)
          It returns the number of minutes between two Gregorian Calendar dates
static int getMinutes(String date1, String date2)
          It returns the number of minutes between two string type dates.
static String getThisMonth()
          get this month including this year
static String getThisYear()
          get this year
static String getYesterday()
          get yesaterday
static String getYesterday(String format)
          get yesaterday with format
static boolean greaterThan(Date date1, Date date2)
          Compares two Dates for ordering.
static boolean greaterThan(Date date1, String date2)
          Compares two Dates for ordering.
static boolean greaterThan(Date date1, String date2, String date2format)
          Compares two Dates for ordering.
static Calendar string2Calender(String str)
          convert String to java.util.Calendar
static Date string2Date(String str)
          convert String to java.util.Date
static Date string2Date(String str, String format)
          convert String to java.util.Date
static Date string2SQLDate(String date)
          convert String to java.sql.Date type
static Date string2SQLDate(String date, String format)
          convert String to java.sql.Date type
static Timestamp string2Timestamp(String str)
          convert String to java.sq.Timestamp
static Timestamp string2Timestamp(String str, String format)
          convert String to java.sq.Timestamp
static String timestamp2String(Timestamp date)
          convert java.sql.Timestamp to String type
static String timestamp2String(Timestamp date, String format)
          convert java.sql.Timestamp to String type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEndDate

public static String getEndDate(String startDay,
                                int intervalDays)
getting end date intervalDays <= 40

Parameters:
startDay - start day (yyyy-MM-dd)
intervalDays - interval days
Returns:
day after interval days from start day (yyyy-MM-dd)

getDefaultDatePattern

public static String getDefaultDatePattern()
Return default datePattern (yyyy-MM-dd)

Returns:
a string representing the date pattern on the UI

greaterThan

public static boolean greaterThan(Date date1,
                                  String date2)
Compares two Dates for ordering.

Parameters:
date1 - Date to be compared.
date2 - another Date String to be compared. (yyyy-MM-dd)
Returns:
the value true if the date1 is equal to date2 or date1 is after the date2. the value false if the date1 is before the date2.

greaterThan

public static boolean greaterThan(Date date1,
                                  String date2,
                                  String date2format)
Compares two Dates for ordering.

Parameters:
date1 - Date to be compared.
date2 - another Date String to be compared. (The format equals date2format that input argument)
date2format - String date format
Returns:
the value true if date1 is after the date2. the value false if the date1 is equal to date2 or the date1 is before the date2.

greaterThan

public static boolean greaterThan(Date date1,
                                  Date date2)
Compares two Dates for ordering.

Parameters:
date1 - Date to be compared.
date2 - another Date to be compared.
Returns:
the value true if or date1 is after the date2. the value false if the date1 is equal to date2 the date1 is before the date2.

equals

public static boolean equals(Date date1,
                             String date2)
Compares two dates for equality.

Parameters:
date1 - the Date to compare with.
date2 - the other Date String to compare with. (yyyy-MM-dd)
Returns:
true if the Dates are the same; false otherwise.

equals

public static boolean equals(Date date1,
                             String date2,
                             String date2format)
Compares two dates for equality.

Parameters:
date1 - the Date to compare with.
date2 - the other Date String to compare with. (The format equals date2format that input argument)
date2format - String Date format
Returns:
true if the Dates are the same; false otherwise.

equals

public static boolean equals(Date date1,
                             Date date2)
Compares two dates for equality.

Parameters:
date1 - the Date to compare with.
date2 - the other Date to compare with.
Returns:
true if the Dates are the same; false otherwise.

string2SQLDate

public static Date string2SQLDate(String date)
                           throws Exception
convert String to java.sql.Date type

Parameters:
date - the String Date to be converted (yyyy-MM-dd)
Returns:
java.sql.Date
Throws:
Exception - fail to convert string to SQLDate

string2SQLDate

public static Date string2SQLDate(String date,
                                  String format)
                           throws Exception
convert String to java.sql.Date type

Parameters:
date - the String Date to be converted
format - date format to be converted.
Returns:
java.sql.Date
Throws:
Exception - fail to convert String to java.sql.Date

date2String

public static String date2String(Date date)
convert java.util.Date to String type

Parameters:
date - the Date to be converted
Returns:
a string representing the date (yyyy-MM-dd)

date2String

public static String date2String(Date date,
                                 String format)
convert java.util.Date to String type

Parameters:
date - the Date to be converted
format - converted date format
Returns:
a string representing the date (The format equals format that input argument)

string2Date

public static Date string2Date(String str)
convert String to java.util.Date

Parameters:
str - the String Date to be converted (yyyy-MM-dd)
Returns:
java.util.Date

string2Date

public static Date string2Date(String str,
                               String format)
convert String to java.util.Date

Parameters:
str - the String Date to be converted (The format equals format that input argument)
format - converted date format
Returns:
java.util.Date

string2Timestamp

public static Timestamp string2Timestamp(String str,
                                         String format)
convert String to java.sq.Timestamp

Parameters:
str - the String Date to be converted (The format equals format that input argument)
format - converted date format
Returns:
java.sql.Timestamp

string2Timestamp

public static Timestamp string2Timestamp(String str)
convert String to java.sq.Timestamp

Parameters:
str - the String Date to be converted (yyyy-MM-dd)
Returns:
java.sql.Timestamp

timestamp2String

public static String timestamp2String(Timestamp date)
convert java.sql.Timestamp to String type

Parameters:
date - the Date to be converted
Returns:
a string representing the date (yyyy-MM-dd)

timestamp2String

public static String timestamp2String(Timestamp date,
                                      String format)
convert java.sql.Timestamp to String type

Parameters:
date - the Date to be converted (The format equals format that input argument)
format - Date format
Returns:
a string representing the date

string2Calender

public static Calendar string2Calender(String str)
convert String to java.util.Calendar

Parameters:
str - the String Date to be converted (yyyyMMddHHmmss)
Returns:
java.util.Calendar

calendar2String

public static String calendar2String(Calendar calendar)
convert java.util.Calendar to String

Parameters:
calendar - the Calendar to be converted
Returns:
a string representing the date (yyyyMMddHHmmss)

getMinutes

public static int getMinutes(Calendar cal1,
                             Calendar cal2)
It returns the number of minutes between two Gregorian Calendar dates

Parameters:
cal1 - the Calendar to calculate
cal2 - another Calendar to calculate
Returns:
minutes between cal1 and cal2

getMinutes

public static int getMinutes(String date1,
                             String date2)
It returns the number of minutes between two string type dates.

Parameters:
date1 - the String Date to calculate (yyyyMMddHHmmss)
date2 - another String Date to calculate (yyyyMMddHHmmss)
Returns:
minutes between date1 and date2

getDays

public static int getDays(Calendar cal1,
                          Calendar cal2)
It returns the number of days between two Gregorian Calendar dates (e.g. cal1: 2005-08-15, cal2: 2005-09-14 => 30 days)

Parameters:
cal1 - the Calendar to calculate
cal2 - another Calendar to calculate
Returns:
days between cal1 and cal2

getDays

public static int getDays(String date1,
                          String date2)
It returns the number of days between two string type dates.

Parameters:
date1 - the String Date to calculate (yyyyMMddHHmmss)
date2 - another String Date to calculate (yyyyMMddHHmmss)
Returns:
minutes between date1 and date2

getCurrentTime

public static String getCurrentTime()
get current system time

Returns:
String representing current system time (yyyy-MM-dd HH:mm)

getCurrentTime

public static String getCurrentTime(String format)
get current time with date format

Parameters:
format - Date format
Returns:
String representing current time

getCurrentDay

public static String getCurrentDay()
get current day

Returns:
String representing current day (yyyy-MM-dd)

getThisMonth

public static String getThisMonth()
get this month including this year

Parameters:
format - Date format
Returns:
String representing this month (yyyy-MM)

getThisYear

public static String getThisYear()
get this year

Returns:
String representing this year (yyyy)

getCurrentHour

public static String getCurrentHour()
get current hour

Returns:
String representing current hour (HH:mm)

getYesterday

public static String getYesterday()
get yesaterday

Returns:
String representing yesterday (yyyy-MM-dd)

getYesterday

public static String getYesterday(String format)
get yesaterday with format

Parameters:
format - Date format
Returns:
String representing yesterday

getDates

public static String[] getDates(String startDay,
                                String endDay)
find dates between startDay and endDay

Parameters:
startDay - start day (yyyy-MM-dd)
endDay - end day (yyyy-MM-dd)
Returns:
String array of dates between startDay and endDay

getDates

public static String[] getDates(String startDay,
                                String endDay,
                                String format)
find dates between startDay and endDay

Parameters:
startDay - start day
endDay - end day
format - date format
Returns:
String array of dates between startDay and endDay

Anyframe Core

Copyright © 2008-2009 Samsung SDS. All Rights Reserved.