Java Month Convert monthOfDate(Date s)

Here you can find the source of monthOfDate(Date s)

Description

month Of Date

License

Open Source License

Declaration

static public int monthOfDate(Date s) throws ParseException 

Method Source Code

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

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*w w  w . j  a v  a  2 s.  com*/
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    static public int monthOfDate(Date s) throws ParseException {
        String d = FORMAT_YYYY_MM_DD.format(s);
        return Integer.parseInt(d.substring(5, 7));
    }

    static public String format(Date date, String formatText) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(formatText);
        return format.format(date);
    }
}

Related

  1. monthAgo()
  2. monthConvertToNumber(String str)
  3. monthformMatDate(Date date)
  4. monthIndexAsString(Integer index, Integer offset)
  5. monthNumber(String s)
  6. monthsBetween(String from, String to)
  7. monthStringToInt(String month)
  8. nextMonth()
  9. nextMonth(Date date)