org.dmonix.util
Class DateHandler

java.lang.Object
  extended byorg.dmonix.util.DateHandler

public abstract class DateHandler
extends java.lang.Object

Utility class for managing dates and times.
Primarily used for formatting string into dates and vice versa. Copyright: Copyright (c) Peter Nerg

Company: dmonix

Version:
1.3.1
Author:
Peter Nerg

Field Summary
static java.text.SimpleDateFormat[] DATE_FORMATS
          The built in default supported date formats.
 
Method Summary
static java.lang.String getDate(long millis, java.lang.String dateFormat)
          Formats the given time in milliseconds to a chosen format ex. yyyyy.MMMMM.dd kk:mm ex. yyyyy-MM-dd
static java.util.Date getDate(java.lang.String dateString)
          Parse a Date object from a date string.
static java.util.Date getDate(java.lang.String dateString, java.lang.String dateFormat)
          Parse a Date object from a date string.
static int getDaysBetweenDates(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
          Returns the number of days between two dates.
static long getMillis(int year, int month, int day)
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.
static long getMillis(int year, int month, int day, int hour, int minute)
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.
static long getMillis(int year, int month, int day, int hour, int minute, int second)
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.
static long getMillis(int year, int month, int day, int hour, int minute, int second, int millis)
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.
static java.lang.String getToday(java.lang.String dateFormat)
          Returns today in a formatted string ex. yyyy.MMMMM.dd kk:mm ex. yyyy-MM-dd
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_FORMATS

public static final java.text.SimpleDateFormat[] DATE_FORMATS
The built in default supported date formats.

Method Detail

getDate

public static java.lang.String getDate(long millis,
                                       java.lang.String dateFormat)
Formats the given time in milliseconds to a chosen format ex. yyyyy.MMMMM.dd kk:mm ex. yyyyy-MM-dd

Parameters:
millis - milliseconds since January 1, 1970, 00:00:00 GMT
dateFormat - The format to return the string in
Returns:
String

getDate

public static java.util.Date getDate(java.lang.String dateString)
Parse a Date object from a date string.
The method will attempt to use one of the default date formats

Parameters:
dateString - The date string
Returns:
The Date object or null if unable to parse
See Also:
DATE_FORMATS

getDate

public static java.util.Date getDate(java.lang.String dateString,
                                     java.lang.String dateFormat)
Parse a Date object from a date string.

Parameters:
dateString - The date string
dateFormat - The date format to use for the parse
Returns:
The Date object or null if unable to parse

getDaysBetweenDates

public static int getDaysBetweenDates(int startYear,
                                      int startMonth,
                                      int startDay,
                                      int endYear,
                                      int endMonth,
                                      int endDay)
Returns the number of days between two dates.

Parameters:
startYear - start year
startMonth - start month [1-12]
startDay - start day
endYear - end year
endMonth - end month [1-12]
endDay - end day
Returns:
number of days

getMillis

public static long getMillis(int year,
                             int month,
                             int day)
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.

Parameters:
year - The year
month - The month
day - Day of the month
Returns:
long

getMillis

public static long getMillis(int year,
                             int month,
                             int day,
                             int hour,
                             int minute)
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.

Parameters:
year - The year
month - The month
day - Day of the month
hour - The hour
minute - The minute of the hour
Returns:
long

getMillis

public static long getMillis(int year,
                             int month,
                             int day,
                             int hour,
                             int minute,
                             int second)
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.

Parameters:
year - The year
month - The month
day - Day of the month
hour - The hour
minute - The minutes of the hour
second - The seconds of the minute
Returns:
long

getMillis

public static long getMillis(int year,
                             int month,
                             int day,
                             int hour,
                             int minute,
                             int second,
                             int millis)
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT for the given date.

Parameters:
year - The year
month - The month
day - Day of the month
hour - The hour
minute - The minutes of the hour
second - The seconds of the minute
millis - The milliseconds of the second
Returns:
long

getToday

public static java.lang.String getToday(java.lang.String dateFormat)
Returns today in a formatted string ex. yyyy.MMMMM.dd kk:mm ex. yyyy-MM-dd

Parameters:
dateFormat - The format to return the string in
Returns:
String


Copyright © 1998-2005 dmonix.org Peter Nerg, All Rights Reserved.