Java SQL Date Month getMonthFromYMD(Date ymd)

Here you can find the source of getMonthFromYMD(Date ymd)

Description

get Month From YMD

License

Open Source License

Declaration

public static String getMonthFromYMD(Date ymd) 

Method Source Code


//package com.java2s;
import java.sql.Date;
import java.sql.Time;

import java.text.*;

public class Main {
    public static final String DEFAULT_DATE_YMD_FORMAT = "yyyy-MM-dd";
    public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";

    public static String getMonthFromYMD(Date ymd) {

        return getMonthFromYMD(toString(ymd));
    }/* www.  j av a  2 s  .  c  o m*/

    public static String getMonthFromYMD(String ymd) {

        if (ymd == null || ymd.length() != DEFAULT_DATE_YMD_FORMAT.length()) {
            return null;
        }

        return ymd.substring(5, 7);
    }

    public static String toString(Date date) {
        return toString((java.util.Date) date);
    }

    public static String toString(java.util.Date date) {
        return toString(date, DEFAULT_DATE_YMD_FORMAT);
    }

    public static String toString(Date date, String format) {
        return toString((java.util.Date) date, format);
    }

    public static String toString(java.util.Date date, String format) {

        if (date == null) {
            return null;
        }

        if (format == null) {
            throw new IllegalArgumentException("The value of an argument is inaccurate.");
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);

        return sdf.format(date);
    }

    public static String toString(Time time, String format) {

        if (time == null) {
            return null;
        }

        if (format == null) {
            throw new IllegalArgumentException("The value of an argument is inaccurate.");
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);

        return sdf.format(time);
    }

    public static String toString(Time time) {
        return toString(time, DEFAULT_TIME_FORMAT);
    }
}

Related

  1. getMonth(final java.sql.Date date)
  2. getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)
  3. getMonthBefroe(Date date)
  4. getMonthDate(Date myDate, int month)
  5. getMonthDays(java.sql.Date date)
  6. getMonthStart(Date stamp)
  7. getMulmonthday(String startdate, String enddate)
  8. getNextMonthFirstDate(java.sql.Date date)
  9. getNextMonthStartDate(Date date)