ch.bouquet.jpa.util
Class DateHelper

java.lang.Object
  extended by ch.bouquet.jpa.util.DateHelper

public class DateHelper
extends java.lang.Object

CAS Enterprise Application Development mit Java EE (EADJ) - 2007
Modul: Data-Tier (JPA)
User admininstration (examination question)
Description:
date helper class to format date strings into timestamps and vice versa.

Copyright (c) 2007 bouquet dot ch, 3032 Hinterkappelen. All rights reseved.

Version:
1.0 - 25.05.2007
Author:
Marc Bouquet ( marc at bouquet dot ch, Swiss )

Field Summary
static java.lang.String DATE_FORMAT
          Date string format in days, month and years
static java.lang.String DATE_FORMAT_COMPLIT
          Date string format in days, month, years, hours, minute and secounds
static java.lang.String DATE_SEPARATOR
          Date separator string, used to parse date strings
static java.lang.String YEAR_FORMAT
          Year format including centruy
 
Constructor Summary
DateHelper()
           
 
Method Summary
private static java.lang.String addLeadingZero(int text, int len)
          add leading zero's to a given string
static java.util.Calendar toCalendar(java.lang.String date)
          Convert date string with the format dd.mm.yyyy to a calendar type
private static java.lang.String toString(java.util.Calendar calendar)
          return calendar as date in the format dd.mm.yyyy or an empty string if calendar is null.
static java.lang.String toString(java.util.Date date)
          return date as string in the format dd.mm.yyyy HH:mm:ss or an empty string if date is null.
static java.lang.String toString(java.sql.Timestamp timestamp)
          return timestamp as date in the format dd.mm.yyyy or an empty string if the timestamp is null
static java.sql.Timestamp toTimestamp(java.lang.String date)
          Convert date string with the format dd.mm.yyyy to a timestamp type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_SEPARATOR

public static final java.lang.String DATE_SEPARATOR
Date separator string, used to parse date strings

See Also:
Constant Field Values

DATE_FORMAT

public static final java.lang.String DATE_FORMAT
Date string format in days, month and years

See Also:
Constant Field Values

DATE_FORMAT_COMPLIT

public static final java.lang.String DATE_FORMAT_COMPLIT
Date string format in days, month, years, hours, minute and secounds

See Also:
Constant Field Values

YEAR_FORMAT

public static final java.lang.String YEAR_FORMAT
Year format including centruy

See Also:
Constant Field Values
Constructor Detail

DateHelper

public DateHelper()
Method Detail

toCalendar

public static java.util.Calendar toCalendar(java.lang.String date)
Convert date string with the format dd.mm.yyyy to a calendar type

Parameters:
date - as string
Returns:
calendar

toTimestamp

public static java.sql.Timestamp toTimestamp(java.lang.String date)
Convert date string with the format dd.mm.yyyy to a timestamp type

Parameters:
date - as string
Returns:
timestamp

toString

public static java.lang.String toString(java.sql.Timestamp timestamp)
return timestamp as date in the format dd.mm.yyyy or an empty string if the timestamp is null

Parameters:
timestamp - given timestamp
Returns:
String timestamp as date string or empty string if null

toString

private static java.lang.String toString(java.util.Calendar calendar)
return calendar as date in the format dd.mm.yyyy or an empty string if calendar is null.

Parameters:
calendar - given calendar
Returns:
String calendar as date string or empty string if null

toString

public static java.lang.String toString(java.util.Date date)
return date as string in the format dd.mm.yyyy HH:mm:ss or an empty string if date is null.

Parameters:
date - Date
Returns:
String formatted date as string or empty string if null

addLeadingZero

private static java.lang.String addLeadingZero(int text,
                                               int len)
add leading zero's to a given string

Parameters:
text - given string (sample = "2")
len - total length of new string (sample = 3)
Returns:
String new string with leading zeros (sample = "002")


Copyright © 2007 - bouquet dot ch, 3032 Hinterkappelen. All Rights Reserved.