sascha@894: /** sascha@894: * Title: DateUtisl, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.java,v 1.2 2008/08/18 14:50:33 drewnak Exp $ sascha@894: * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.java,v $ sascha@894: * created by: Stefan Blume (blume) sascha@894: * erstellt am: 21.12.2007 sascha@894: * Copyright: con terra GmbH, 2005 sascha@894: * sascha@894: * modified by: $Author: drewnak $ sascha@894: * modified on: $Date: 2008/08/18 14:50:33 $ sascha@894: * Version: $Revision: 1.2 $ sascha@894: * TAG: $Name: $ sascha@894: * locked from: $Locker: $ sascha@894: * CVS State: $State: Exp $ sascha@894: * Project: $ProjectName$ sascha@894: */ sascha@894: package de.intevation.gnv.geobackend.util; sascha@894: sascha@894: import java.text.SimpleDateFormat; sascha@894: import java.util.Date; sascha@894: sascha@894: import org.apache.log4j.Logger; sascha@894: sascha@894: /** sascha@894: * The class DateUtils fulfills the following purposes: sascha@894: * @author blume sascha@894: * @author Tim Englich sascha@894: */ sascha@894: public class DateUtils { sascha@894: sascha@894: /** sascha@894: * Default Logging instance sascha@894: */ sascha@894: private static Logger sLogger = Logger.getLogger(DateUtils.class); sascha@894: sascha@894: /** sascha@894: * The Dateformat which will be used e.g for Querying the Database sascha@894: */ sascha@894: public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss"; sascha@894: sascha@894: private static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss"; sascha@894: sascha@894: /** sascha@894: * The Method returns a Date using the given pattern as a String sascha@894: * @param pDate The Date which should be formatted sascha@894: * @param sPattern The Pattern which should be used. sascha@894: * @return the Date formatted a a String sascha@894: */ sascha@894: public static String getPatternedDate(Date pDate, String sPattern) { sascha@894: SimpleDateFormat fmt = new SimpleDateFormat(); sascha@894: fmt.applyPattern(sPattern); sascha@894: return fmt.format(pDate); sascha@894: } sascha@894: sascha@894: /** sascha@894: * Returns the Date as a String formated using the sascha@894: * DateUtils.DATE_PATTERN format- sascha@894: * @param pDate the Date which should be formatted sascha@894: * @return the given Data as a String sascha@894: */ sascha@894: public static String getPatternedDateAmer(Date pDate) { sascha@894: String sStr = getPatternedDate(pDate, DATE_PATTERN); sascha@894: return sStr; sascha@894: } sascha@894: sascha@894: /** sascha@894: * This method decodes a Datevalue from the given String useing the sascha@894: * DateUtils.DATE_PATTERN1 format- sascha@894: * @param sStr The String which contains the encoded Datevalue sascha@894: * @return the decoded Datevalue as an Date-object. sascha@894: * @throws Exception throws all Expetion which occurs during the Process. sascha@894: */ sascha@894: public static Date getDateFromString (String sStr)throws Exception { sascha@894: Date date = getDateFromString (sStr, DATE_PATTERN1); sascha@894: return date; sascha@894: } sascha@894: sascha@894: /** sascha@894: * Formats a given Date encoded as a String using the given Pattern sascha@894: * into a Date Object. sascha@894: * @param sStr The String with the encoded DateValue sascha@894: * @param sPattern The pattern which should be used to decode the Date sascha@894: * @return the given Datevalue as an Date-Object. sascha@894: * @throws Exception throws all Expetion which occurs during the Process. sascha@894: */ sascha@894: public static Date getDateFromString (String sStr, sascha@894: String sPattern)throws Exception { sascha@894: SimpleDateFormat fmt = new SimpleDateFormat(); sascha@894: fmt.applyPattern(sPattern); sascha@894: return fmt.parse(sStr); sascha@894: } sascha@894: }