Travis: here you go..

import java.text.SimpleDateFormat;
import java.util.Date;

public class ECRCDateFormat extends SimpleDateFormat{
 
    String newFormat = "MM'/'dd'/'yyyy";
    /** Creates new NewDateFormat objects.
     */
    public ECRCDateFormat(){
        super("yyyy'-'MM'-'dd");
    }
 
    /** Creates new NewDateFormat objects from a given old format.
     * @param oldFormat The String depicting the old format; for example:
     * "yyyy'-'MM'-'dd"
     * @throws Exception Throws exception if this is not a recognizable format for a Date.
     */
    public ECRCDateFormat(String oldFormat) throws Exception{
        super(oldFormat);
    }
 
    /** Getter for newFormat
     * @return newFormat
     */
    public String getNewFormat(){
        return newFormat;
    }
    /** Setter for newFormat
     * @param nf The new format.
     */
    public void setNewFormat(String nf){
        newFormat = nf;
    }
 
    /** Used to convert a String in the old format as a String in the new format.
     * @param oldText The old date as a String
     * @return The date in the new format as a String.
     */
    public String convert(String oldText){
        Date oldDate;
        String newText = "";
        if (oldText.equalsIgnoreCase(""))
            oldText = "1800-01-01";  //this should tell us we're in trouble!
 
        try{
            oldDate = new Date();
            try{
                oldDate = this.parse(oldText);
                SimpleDateFormat newFormatter = new SimpleDateFormat(newFormat);

                try{
                    newText = newFormatter.format(oldDate);
                }
                catch(Exception e){
                    System.out.println("Cannot parse! " + e);
                }
            }
            catch(Exception e){
                System.out.println("Cannot parse!" + e);
            }
        }
        catch(Exception e){
            System.out.println("Cannot do anything!!!" + e);
        }
 
        return newText;
    }
} //end class def ECRCDateFormat

Geeta

Reply via email to