Java Date Format Pattern getMM(String strDate)

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

Description

Insert the method's description here.

License

Apache License

Parameter

Parameter Description
strDate java.lang.String

Return

int

Declaration

public static int getMM(String strDate) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /** Constante que define el patron estandar de presentacion de fechas */
    private static final String PATRON_FECHA_DEFAULT = "dd/MM/yyyy";

    /**//from  w  w  w  . j a  va2 s .c o  m
     * Insert the method's description here. Creation date: (25/05/2002 08:19:24 p.m.)
     *
     * @param strDate java.lang.String
     * @param pattern DOCUMENT ME!
     *
     * @return int
     */
    public static int getMM(String strDate, String pattern) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(convertStringToDate(strDate, pattern));

        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * Insert the method's description here. Creation date: (25/05/2002 08:19:24 p.m.)
     *
     * @param strDate java.lang.String
     *
     * @return int
     */
    public static int getMM(String strDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(convertStringToDate(strDate));

        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * Convertidor de cadenas con el patron 'dd/MM/yyyy' a fechas
     *
     * @param stringDate La cadena a transformar
     *
     * @return La fecha transformada
     */
    public static java.util.Date convertStringToDate(String stringDate) {
        return convertStringToDate(stringDate, PATRON_FECHA_DEFAULT);
    }

    public static java.util.Date convertStringToDate(String stringDate,
            String pattern) {
        java.util.Date date = null;

        try {
            SimpleDateFormat formatter = new SimpleDateFormat(pattern);
            formatter.setLenient(true);
            date = formatter.parse(stringDate);
        } catch (Exception e) {
            date = new java.util.Date();
        }

        return date;
    }
}

Related

  1. getFormatToSecsForFilename()
  2. getHeaderFormat()
  3. getLenientFormat(String format)
  4. getMM()
  5. getMM(Date date)
  6. getMMdd()
  7. getMMDDYYHHMM()
  8. getMMDDYYYY(final Date date, final String separator)
  9. getMomentFormatter()