comparison 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
comparison
equal deleted inserted replaced
875:5e9efdda6894 899:3f9fc88aec2b
1 /**
2 * 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 $
3 * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.java,v $
4 * created by: Stefan Blume (blume)
5 * erstellt am: 21.12.2007
6 * Copyright: con terra GmbH, 2005
7 *
8 * modified by: $Author: drewnak $
9 * modified on: $Date: 2008/08/18 14:50:33 $
10 * Version: $Revision: 1.2 $
11 * TAG: $Name: $
12 * locked from: $Locker: $
13 * CVS State: $State: Exp $
14 * Project: $ProjectName$
15 */
16 package de.intevation.gnv.geobackend.util;
17
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20
21 import org.apache.log4j.Logger;
22
23 /**
24 * The class <code>DateUtils</code> fulfills the following purposes:
25 * @author blume
26 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
27 */
28 public class DateUtils {
29
30 /**
31 * Default Logging instance
32 */
33 private static Logger sLogger = Logger.getLogger(DateUtils.class);
34
35 /**
36 * The Dateformat which will be used e.g for Querying the Database
37 */
38 public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss";
39
40 private static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss";
41
42 /**
43 * The Method returns a Date using the given pattern as a String
44 * @param pDate The Date which should be formatted
45 * @param sPattern The Pattern which should be used.
46 * @return the Date formatted a a String
47 */
48 public static String getPatternedDate(Date pDate, String sPattern) {
49 SimpleDateFormat fmt = new SimpleDateFormat();
50 fmt.applyPattern(sPattern);
51 return fmt.format(pDate);
52 }
53
54 /**
55 * Returns the Date as a String formated using the
56 * <code>DateUtils.DATE_PATTERN</code> format-
57 * @param pDate the Date which should be formatted
58 * @return the given Data as a String
59 */
60 public static String getPatternedDateAmer(Date pDate) {
61 String sStr = getPatternedDate(pDate, DATE_PATTERN);
62 return sStr;
63 }
64
65 /**
66 * This method decodes a Datevalue from the given String useing the
67 * <code>DateUtils.DATE_PATTERN1</code> format-
68 * @param sStr The String which contains the encoded Datevalue
69 * @return the decoded Datevalue as an Date-object.
70 * @throws Exception throws all Expetion which occurs during the Process.
71 */
72 public static Date getDateFromString (String sStr)throws Exception {
73 Date date = getDateFromString (sStr, DATE_PATTERN1);
74 return date;
75 }
76
77 /**
78 * Formats a given Date encoded as a String using the given Pattern
79 * into a Date Object.
80 * @param sStr The String with the encoded DateValue
81 * @param sPattern The pattern which should be used to decode the Date
82 * @return the given Datevalue as an Date-Object.
83 * @throws Exception throws all Expetion which occurs during the Process.
84 */
85 public static Date getDateFromString (String sStr,
86 String sPattern)throws Exception {
87 SimpleDateFormat fmt = new SimpleDateFormat();
88 fmt.applyPattern(sPattern);
89 return fmt.parse(sStr);
90 }
91 }

http://dive4elements.wald.intevation.org