diff geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 899:3f9fc88aec2b

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

http://dive4elements.wald.intevation.org