Java Month Get getMonth(String datetime)

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

Description

get Month

License

Open Source License

Declaration

public static int getMonth(String datetime) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    public static int getMonth(String datetime) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(parseDate(datetime));

        return cal.get(Calendar.MONTH) + 1;
    }// www  .j a va2 s.co m

    public static Date parseDate(String datetime) {
        try {
            return DATE_FORMAT.parse(datetime);
        } catch (ParseException e) {
            return new Date();
        }
    }

    public static Date parse(String datetime) {
        try {
            return FORMAT.parse(datetime);
        } catch (ParseException e) {
            return new Date();
        }
    }
}

Related

  1. getMonth(String aDate)
  2. getMonth(String date)
  3. getMonth(String date)
  4. getMonth(String date)
  5. getMonth(String dateKey)
  6. getMonth(String day)
  7. getMonth(String f)
  8. getMonth(String name)
  9. getMonth(String pFormattedDate)