view geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 271:8aad9d098b08

Integrated Patch of issue57 to get some Memoryusage-improvements geo-backend/trunk@248 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 20 Oct 2009 09:57:52 +0000
parents 25be806da62f
children 12f88239fb33
line wrap: on
line source
/**
 * 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);
    } 
    
     
}

http://dive4elements.wald.intevation.org