net.lessy.util
Class DateUtil

java.lang.Object
  extended by net.lessy.util.DateUtil

public class DateUtil
extends Object

Utility-Methods around Date and Time

Author:
Hans Lesmeister

Constructor Summary
DateUtil()
           
 
Method Summary
static Date addDays(Date date, int days)
           
static Date createDate()
          Creates a date based on the actual date but without time-settings, so the time part of this date is 00:00:00.000
static Date createDate(int year, int month, int day)
          Creates a date specified with the passed values
static Calendar getCalendar(Date date)
          Get a calendar
static int getYear(Date date)
          Gets the Year-Part from a date
static void resetTimePart(Calendar calendar)
          Sets the time part in a calendar to zero (Hours, Minutes, Seconds, Milliseconds)
static Date resetTimePart(Date date)
          Sets the time part of a date to zero
static Date setTimeToEndOfDay(Date date)
          Sets the time part to the last second of the day.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtil

public DateUtil()
Method Detail

createDate

public static Date createDate(int year,
                              int month,
                              int day)
Creates a date specified with the passed values

Parameters:
year - Year
month - Month (1-based, so 1 = Jan., 2 = Feb.)
day - Day of the month
Returns:
Date-Instance

createDate

public static Date createDate()
Creates a date based on the actual date but without time-settings, so the time part of this date is 00:00:00.000

Returns:
Date-Instance

resetTimePart

public static void resetTimePart(Calendar calendar)
Sets the time part in a calendar to zero (Hours, Minutes, Seconds, Milliseconds)

Parameters:
calendar - Calendar
Throws:
NullPointerException - if calendar is null

setTimeToEndOfDay

public static Date setTimeToEndOfDay(Date date)
Sets the time part to the last second of the day. This is used for queries with something like "date <= :someDate" and the date values in the table could have a time-part.

Parameters:
date - Date. If null the the actual date will be taken
Returns:
date with the time-part set to 23:59:59 999

resetTimePart

public static Date resetTimePart(Date date)
Sets the time part of a date to zero

Parameters:
date - Date
Returns:
new Date with time part set to zero

getCalendar

public static Calendar getCalendar(Date date)
Get a calendar

Parameters:
date - a date or null
Returns:
calendar with the passe date set. If date is null then calendar represants the actual date

addDays

public static Date addDays(Date date,
                           int days)

getYear

public static int getYear(Date date)
Gets the Year-Part from a date

Parameters:
date - Date to extract the year from. If null, then the actual year is returned
Returns:
The year, extracted from the date


Copyright © 2012. All Rights Reserved.