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 org.apache.log4j.Logger;
tim@129:
tim@129: import java.text.SimpleDateFormat;
tim@129: import java.util.Date;
tim@129:
tim@129:
tim@129: /**
tim@129: * The class DateUtisl
fulfills the following purposes:
tim@129: *
tim@129: *
tim@129: *
tim@129: *
tim@129: * @author blume
tim@129: * @version 1.0
tim@129: * @serial 1.0
tim@129: * @see
tim@129: * @since 21.12.2007 10:34:01
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: private static boolean sDebug = sLogger.isDebugEnabled();
tim@129:
tim@142: public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss";
tim@142: public static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss";
tim@142: public static final String TimeRangeFilterPattern = "yyyy-MM-dd'T'HH:mm:ssZ";
tim@142: public static final String TimeRangeFilterFormPattern = "dd.MM.yyyy HH:mm";
tim@129:
tim@129: public static String getPatternedDateSDF(Date pDate) {
tim@129: SimpleDateFormat fmt = new SimpleDateFormat();
tim@129: fmt.applyPattern(DATE_PATTERN);
tim@129: return fmt.format(pDate);
tim@129: }
tim@129:
tim@129: public static String getPatternedDate(Date pDate, String sPattern) {
tim@129: // DateTimeZone.setDefault(DateTimeZone.UTC);
tim@129: // DateTime dtf = new DateTime (pDate);
tim@129: // String sStr = dtf.toString(sPattern);
tim@129: // return sStr;
tim@129: SimpleDateFormat fmt = new SimpleDateFormat();
tim@129: fmt.applyPattern(sPattern);
tim@129: return fmt.format(pDate);
tim@129: }
tim@129:
tim@129: public static String getPatternedDateAmer(Date pDate) {
tim@129:
tim@129: String sStr = getPatternedDate(pDate, DATE_PATTERN);
tim@129: return sStr;
tim@129: }
tim@129:
tim@129: public static String getPatternedDateGerm(Date pDate) {
tim@129:
tim@129: String sStr = getPatternedDate(pDate, DATE_PATTERN1);
tim@129: return sStr;
tim@129: }
tim@129:
tim@129: public static String getPatternedDateTimeRangeFilter(Date pDate) {
tim@129:
tim@129: String sStr = getPatternedDate(pDate, TimeRangeFilterPattern);
tim@129: return sStr;
tim@129: }
tim@129:
tim@129: public static String getPatternedDateTimeRangeFilterForm(Date pDate) {
tim@129:
tim@129: String sStr = getPatternedDate(pDate, TimeRangeFilterFormPattern);
tim@129: return sStr;
tim@129: }
tim@129:
tim@129: public synchronized static Date getDateFromStringSDF (String sStr)throws Exception {
tim@129: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
tim@129: Date date = (Date)formatter.parse(sStr);
tim@129: return date;
tim@129: }
tim@129:
tim@129: public static Date getDateFromString (String sStr)throws Exception {
tim@129:
tim@129: Date date = getDateFromString (sStr, DATE_PATTERN1);
tim@129: return date;
tim@129: }
tim@129:
tim@129: public static Date getDateFromStringTimeRangeFilter (String sStr)throws Exception {
tim@129:
tim@129: Date date = getDateFromString (sStr, TimeRangeFilterPattern);
tim@129: return date;
tim@129: }
tim@129:
tim@129: public static Date getDateFromStringTimeRangeFilterForm (String sStr)throws Exception {
tim@129:
tim@129: Date date = getDateFromString (sStr, TimeRangeFilterFormPattern);
tim@129: return date;
tim@129: }
tim@129:
tim@129: public static Date getDateFromString (String sStr, String sPattern)throws Exception {
tim@129: // DateTime dtf = null;
tim@129: // DateTimeZone.setDefault(DateTimeZone.UTC);
tim@129: //
tim@129: // dtf = DateTimeFormat.forPattern(sPattern).parseDateTime(sStr);
tim@129: //
tim@129: // Date date = dtf.toDate();
tim@129: //
tim@129: // return date;
tim@129: SimpleDateFormat fmt = new SimpleDateFormat();
tim@129: fmt.applyPattern(sPattern);
tim@129: return fmt.parse(sStr);
tim@129: }
tim@129:
tim@129:
tim@129: }