Java Day getDaysForDate(String date)

Here you can find the source of getDaysForDate(String date)

Description

get Days For Date

License

Open Source License

Declaration

public static int getDaysForDate(String date) 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

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

public class Main {

    public static int getDaysForDate(String date) {
        Date curDate = strToDate(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(curDate);// w ww  . ja va  2 s .  co m
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    public static Date strToDate(String strDate) {
        return strToDate(strDate, "yyyy-MM-dd");
    }

    public static Date strToDate(String strDate, String format) {
        if (strDate == null) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
}

Related

  1. getDays(Date day, int preDays, String format)
  2. getDays(Date sd, Date ed)
  3. getDays(String yyyy)
  4. getDaysAgo(int interval)
  5. getDaysByYearMonth(String ym)
  6. getDaysforYear()
  7. getDaysFrom2Dates(Calendar calendar1, Calendar calendar2)
  8. getDaysLater(int day)
  9. getDaysMonthYear(Date date)