Java SQL Date getDayOfPerMonth(String theDataStr)

Here you can find the source of getDayOfPerMonth(String theDataStr)

Description

get Day Of Per Month

License

Open Source License

Declaration

public static Date getDayOfPerMonth(String theDataStr) 

Method Source Code

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

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

public class Main {
    private static final int[] DAY_OF_MONTH = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    public static Date getDayOfPerMonth(String theDataStr) {
        Date theDate = java.sql.Date.valueOf(theDataStr);
        Calendar c = new GregorianCalendar();
        c.setTime(theDate);/*from w  w w. j a  v a  2s . c  om*/
        int day = c.get(Calendar.DAY_OF_MONTH);
        if (day <= 10) {
            c.set(Calendar.DAY_OF_MONTH, 1);
        } else if (day > 10 && day <= 20) {
            c.set(Calendar.DAY_OF_MONTH, 11);
        } else {
            c.set(Calendar.DAY_OF_MONTH, 21);
        }
        c.add(Calendar.DAY_OF_MONTH, -1);

        return new Date(c.getTime().getTime());
    }

    public static int get(Date date, int type) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(type);
    }

    public static String getTime(Date dt, String format) {
        SimpleDateFormat st = new SimpleDateFormat(format);
        return st.format(dt);
    }
}

Related

  1. convertTo(Class clazz, Object obj)
  2. convertTo(final Class> clazz, Object obj)
  3. getClasses()
  4. getCurrDay()
  5. getCurrentYear()
  6. getDiffDays(String begin_dt, String end_dt)
  7. getEndWeekDayOfMonth(String year, String month)
  8. getFileName()
  9. getFirstDayOfNextMonth()