com.googlecode.jpattern.core.util
Class DateHelper

java.lang.Object
  extended by com.googlecode.jpattern.core.util.DateHelper

public abstract class DateHelper
extends Object

Author:
Francesco Cina' 27/feb/2011 Utility class for very simple date formatting.

Constructor Summary
DateHelper()
           
 
Method Summary
static int getDay(Date date)
           
static int getDayOfWeek(Date date)
           
static int getHour(Date date)
           
static int getMilliseconds(Date date)
           
static int getMinutes(Date date)
           
static int getMonth(Date date)
           
static int getSeconds(Date date)
           
static int getYear(Date date)
           
static Calendar toCalendar(Date date)
           
static Date toDate(String d)
          Trasforma una stringa secondo il formato dd/mm/yyyy in data.
static Date toDate(String d, String format)
          Trasforma un string in data in base al formato passato
static Date toDate(String d, String format, Locale locale)
           Trasforma una stringa in data; utilizzando il formato corretto e il locale se il formato risulta locale-sensitive.
static String toString(Date d)
          Trasforma una data in stringa secondo il formato dd/mm/yyyy
static String toString(Date d, String format)
          Trasforma una data in stringa in base al formato passato
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateHelper

public DateHelper()
Method Detail

toDate

public static Date toDate(String d)
                   throws Exception
Trasforma una stringa secondo il formato dd/mm/yyyy in data. In caso di errore di conversione viene lanciata un'eccezione

Parameters:
d - String
Throws:
Exception

toDate

public static Date toDate(String d,
                          String format)
                   throws Exception
Trasforma un string in data in base al formato passato

Parameters:
d - String
format - String
Returns:
Date
Throws:
Exception

toDate

public static Date toDate(String d,
                          String format,
                          Locale locale)
                   throws Exception

Trasforma una stringa in data; utilizzando il formato corretto e il locale se il formato risulta locale-sensitive.

Example: String data = "Fri Dec 01 20:24:35 CET 2006"; String format = "EEE MMM dd HH:mm:ss 'CET' yyyy"; Locale locale = Locale.US;

Parameters:
d - String
format - String
locale - Locale
Returns:
Date
Throws:
Exception

toString

public static String toString(Date d)
Trasforma una data in stringa secondo il formato dd/mm/yyyy

Parameters:
d - Date

toString

public static String toString(Date d,
                              String format)
Trasforma una data in stringa in base al formato passato

Parameters:
d - Date
format - String
Returns:
String

toCalendar

public static Calendar toCalendar(Date date)

getYear

public static int getYear(Date date)
Parameters:
date -
Returns:
the year of the input date

getMonth

public static int getMonth(Date date)
Parameters:
date -
Returns:
the month of the input date (0 if January, 1 if February...)

getDay

public static int getDay(Date date)
Parameters:
date -
Returns:
the day of the month of the input date

getDayOfWeek

public static int getDayOfWeek(Date date)
Parameters:
date -
Returns:
0 if sunday, 1 if monday ...

getHour

public static int getHour(Date date)
Parameters:
date -
Returns:
the hour of the input date

getMinutes

public static int getMinutes(Date date)
Parameters:
date -
Returns:
the minutes of the input date

getSeconds

public static int getSeconds(Date date)
Parameters:
date -
Returns:
the seconds of the input date

getMilliseconds

public static int getMilliseconds(Date date)
Parameters:
date -
Returns:
the milliseconds of the input date


Copyright © 2011. All Rights Reserved.