Java SQL Date getWeekOfMonth(String year, String month, String day)

Here you can find the source of getWeekOfMonth(String year, String month, String day)

Description

get Week Of Month

License

Apache License

Declaration

public static int getWeekOfMonth(String year, String month, String day) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {

    public static int getWeekOfMonth(String year, String month, String day) {
        java.sql.Date myDate = getDate(year, month, day);
        int index = 0;
        try {/*from w ww . j  av  a  2  s  . c om*/
            Calendar cal = Calendar.getInstance();
            cal.setTime(myDate);
            index = cal.get(Calendar.DAY_OF_WEEK);
            if (index <= 1) {
                index = 7;
            } else {
                index = index - 1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return index;

    }

    public static java.sql.Date getDate(String year, String month, String day) {
        java.sql.Date result = null;
        try {
            String str = year + "-" + month + "-" + day;
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            java.util.Date date1 = dateFormat.parse(str);
            result = new java.sql.Date(date1.getTime());
        } catch (Exception e) {
            System.out.println("Exception " + e);
        }
        return result;
    }
}

Related

  1. getNow()
  2. getNowHour()
  3. getProtobufClass(Object value, Class protobufClass)
  4. getTodayAndTomorrow()
  5. getWeekNumber()
  6. getYearLater()
  7. hexToBin(String sHexString)
  8. isLastDayOfMonth(String theDataStr)
  9. isSimpleColumnType(Class columnType)