Mercurial > dive4elements > gnv-client
diff geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 662:755dd2fa4a0a 0.5
merged geo-backend/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 25be806da62f |
children | 12f88239fb33 |
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:53 2012 +0200 @@ -0,0 +1,128 @@ +/** + * 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 org.apache.log4j.Logger; + +import java.text.SimpleDateFormat; +import java.util.Date; + + +/** + * The class <code>DateUtisl</code> fulfills the following purposes: + * <ol> + * <li></li> + * </ol> + * + * @author blume + * @version 1.0 + * @serial 1.0 + * @see + * @since 21.12.2007 10:34:01 + */ +public class DateUtils { + + /** + * Default Logging instance + */ + private static Logger sLogger = Logger.getLogger(DateUtils.class); + private static boolean sDebug = sLogger.isDebugEnabled(); + + public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss"; + public static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss"; + public static final String TimeRangeFilterPattern = "yyyy-MM-dd'T'HH:mm:ssZ"; + public static final String TimeRangeFilterFormPattern = "dd.MM.yyyy HH:mm"; + + public static String getPatternedDateSDF(Date pDate) { + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(DATE_PATTERN); + return fmt.format(pDate); + } + + public static String getPatternedDate(Date pDate, String sPattern) { +// DateTimeZone.setDefault(DateTimeZone.UTC); +// DateTime dtf = new DateTime (pDate); +// String sStr = dtf.toString(sPattern); +// return sStr; + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(sPattern); + return fmt.format(pDate); + } + + public static String getPatternedDateAmer(Date pDate) { + + String sStr = getPatternedDate(pDate, DATE_PATTERN); + return sStr; + } + + public static String getPatternedDateGerm(Date pDate) { + + String sStr = getPatternedDate(pDate, DATE_PATTERN1); + return sStr; + } + + public static String getPatternedDateTimeRangeFilter(Date pDate) { + + String sStr = getPatternedDate(pDate, TimeRangeFilterPattern); + return sStr; + } + + public static String getPatternedDateTimeRangeFilterForm(Date pDate) { + + String sStr = getPatternedDate(pDate, TimeRangeFilterFormPattern); + return sStr; + } + + public synchronized static Date getDateFromStringSDF (String sStr)throws Exception { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); + Date date = (Date)formatter.parse(sStr); + return date; + } + + public static Date getDateFromString (String sStr)throws Exception { + + Date date = getDateFromString (sStr, DATE_PATTERN1); + return date; + } + + public static Date getDateFromStringTimeRangeFilter (String sStr)throws Exception { + + Date date = getDateFromString (sStr, TimeRangeFilterPattern); + return date; + } + + public static Date getDateFromStringTimeRangeFilterForm (String sStr)throws Exception { + + Date date = getDateFromString (sStr, TimeRangeFilterFormPattern); + return date; + } + + public static Date getDateFromString (String sStr, String sPattern)throws Exception { +// DateTime dtf = null; +// DateTimeZone.setDefault(DateTimeZone.UTC); +// +// dtf = DateTimeFormat.forPattern(sPattern).parseDateTime(sStr); +// +// Date date = dtf.toDate(); +// +// return date; + SimpleDateFormat fmt = new SimpleDateFormat(); + fmt.applyPattern(sPattern); + return fmt.parse(sStr); + } + + +}