Java Date to Month getMonth(String strDate)

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

Description

get Month

License

Open Source License

Declaration

public static int getMonth(String strDate) 

Method Source Code

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

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {

    public static int getMonth(String strDate) {
        Calendar cal = parseDateTime(strDate);

        return cal.get(Calendar.MONTH) + 1;
    }//from   w ww .j a v  a2s . c o m

    public static Calendar parseDateTime(String baseDate) {
        Calendar cal = null;
        cal = new GregorianCalendar();
        int yy = Integer.parseInt(baseDate.substring(0, 4));
        int mm = Integer.parseInt(baseDate.substring(5, 7)) - 1;
        int dd = Integer.parseInt(baseDate.substring(8, 10));
        int hh = 0;
        int mi = 0;
        int ss = 0;
        if (baseDate.length() > 12) {
            hh = Integer.parseInt(baseDate.substring(11, 13));
            mi = Integer.parseInt(baseDate.substring(14, 16));
            ss = Integer.parseInt(baseDate.substring(17, 19));
        }
        cal.set(yy, mm, dd, hh, mi, ss);
        return cal;
    }
}

Related

  1. getMonth(java.util.Date date)
  2. getMonth(java.util.Date date)
  3. getMonth(java.util.Date date)
  4. getMonth(java.util.Date today)
  5. getMonth(long date, int increment)
  6. getMonthBeginDate()
  7. getMonthBetween(Date data1, Date data2)
  8. getMonthByOffset(Date date, int offset)
  9. getMonthDays(String date)