annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 897:02cd2935b5fa

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

http://dive4elements.wald.intevation.org