Java Month Get getMonth(String f)

Here you can find the source of getMonth(String f)

Description

get Month

License

Apache License

Declaration

public static Integer getMonth(String f) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Integer getMonth(String f) {
        Integer month;//from  w ww.  j  a  v a2  s .  co  m

        try {
            SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
            Date dt1 = format1.parse(f);
            DateFormat format2 = new SimpleDateFormat("MM");
            month = Integer.valueOf(format2.format(dt1));
        } catch (Exception ex) {
            month = new Integer(-1);
        }

        return month;
    }
}

Related

  1. getMonth(String date)
  2. getMonth(String date)
  3. getMonth(String dateKey)
  4. getMonth(String datetime)
  5. getMonth(String day)
  6. getMonth(String name)
  7. getMonth(String pFormattedDate)
  8. getMonth(String quarters)
  9. getMonth(String sMonth)