Java Month Get getMonth(SimpleDateFormat df, String dateStr)

Here you can find the source of getMonth(SimpleDateFormat df, String dateStr)

Description

get Month

License

Open Source License

Declaration

public static int getMonth(SimpleDateFormat df, String dateStr) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static int getMonth(SimpleDateFormat df, String dateStr) {
        Calendar c = Calendar.getInstance();
        try {/*from   w w w.j  av  a  2s  .c o m*/
            c.setTime(df.parse(dateStr));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return c.get(Calendar.MONTH) + 1;
    }

    public static Date parse(SimpleDateFormat df, String date) {
        try {
            return df.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. getMonth(int month)
  2. getMonth(int month)
  3. getMonth(Integer month)
  4. getMonth(long date, int increment)
  5. getMonth(long l)
  6. getMonth(String aDate)
  7. getMonth(String date)
  8. getMonth(String date)
  9. getMonth(String date)