/** Copyright (c) 2007 Ricebridge. BSD License. */ package com.ricebridge.example.updown; import java.text.DateFormat; import java.util.Date; import com.ricebridge.data.sc.DefaultStringConverter; /** A utility class for converting between Date objects and Strings. * You can use this as an example when writing your own String to object * converters. */ public class SqlDateStringConverter extends DefaultStringConverter { private DateFormat mFormat; /** Specify a DateFormat for parsing and generating textual dates. */ public SqlDateStringConverter( DateFormat pFormat ) { mFormat = pFormat; } /** Create a java.sql.Date object from a String. */ protected Object makeObjectImpl( String pString ) throws Exception { return new java.sql.Date( mFormat.parse( pString ).getTime() ); } /** Create a String from a java.sql.Date object. */ protected String makeStringImpl( Object pObject ) { return mFormat.format( new Date( ((java.sql.Date)pObject).getTime() ) ); } }