www.pudn.com > sxg.rar > GwDate.java


/*
 * Copyright (c) 2003 Jens Mueller
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
	This class provides static methods for dealing with date and time values based on the
  	format "yyyy'-'MM'-'dd'T'HH':'mm':'ss"
 
  	@author Jens Mueller
 */

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class GwDate
{
	private static SimpleDateFormat dateFormat = 
													new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss");

	/**
		@return the current date and time based on the system's timezone
	   	 */
	public static String getCurrent()
	{
		return dateFormat.format( Calendar.getInstance( TimeZone.getDefault() ).getTime() );
	}

	/**
		@param subtrahent 	  	@param subtraktor 	  	@return difference of time beetween subtrahent and subtraktor in milliseconds as
	  				 subtrahent - subtraktor 	 */	
	public static long timeDiff( String subtrahent , String subtraktor )
	{
		Date subtrahentDate;
		Date subtraktorDate;
		try
		{
			subtrahentDate = dateFormat.parse( subtrahent );
			subtraktorDate  = dateFormat.parse( subtraktor );
			return subtrahentDate.getTime() - subtraktorDate.getTime(); 
		}
		catch ( ParseException e ) 
		{ 
			return GatewayConf.getCachingTimeSecs() * 1000 + 1; 
		}
	}
}