Listing A
package mypackage1;
 
 
import java.util.StringTokenizer;
 
 
public class FormatDate {
    public FormatDate() {
    }
  
    public static String formatDate(String strUnFormatted) {
        //if null, return an empty string
        String strTemp=((strUnFormatted==null)?"":strUnFormatted);
      
        if(!strTemp.equalsIgnoreCase("")) {
            //split string using StringTokenizer
            StringTokenizer st= new StringTokenizer(strTemp, "-");
          
            String strMM=st.nextToken();
            String strDD=st.nextToken();
            String strYYYY=st.nextToken();
          
            if(strMM.length()<2 && Integer.parseInt(strMM) < 10) {
                //append the zero
               strMM="0"+strMM;
            }
          
            if(strDD.length()<2 &&Integer.parseInt(strDD) < 10) {
                //append zero
               strDD="0"+strDD;
            }
          
            if(strYYYY.length()<4 && Integer.parseInt(strYYYY) < 100) {
                //append 20
               strYYYY="20"+strYYYY;
            }
           strTemp= strMM+"-"+strDD+"-"+strYYYY;
        }
        return strTemp;
    }
 
 
}