title: java program to accept any format of date as input and print the month,
body: <p>java program to accept any format of date as input and print the month,</p>
  
  <p>Is it possible</p>
  
  <p>I tried the following,any other alternative ways/ideas??</p>
  
  <pre><code>import java.text.*;
  
  import java.util.*;
  
  
  public class PrintMonth3{
  
  
      public static void main(String args[])throws Exception{
  
      String patterns[]={"dd.MM.yyyy","dd.MM.yy","dd.MMM.yyyy","dd.MMM.yy","d.MM.yyyy"};
  
      String input="4.06.2011";
  
      for(int i=0;i&lt;patterns.length;i++)
          doPrintMonth(patterns[i],input);
  
      System.out.println("\nNot a valid date format..");
  
  
      }
  
  
  
      public  static void doPrintMonth( String pattern,String input ) {
  
  
      try{
      SimpleDateFormat sdf=new SimpleDateFormat(pattern);
  
      Date output=sdf.parse(input);
  
  
      String mon[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
      int m=output.getMonth();
      System.out.println("\n\t" + mon[m] );
      System.exit(0);
      }
      catch(Exception e){}    
  
  
      }
  
  
  }
  </code></pre>