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