Java Month Day getMonthWeek(String curday)

Here you can find the source of getMonthWeek(String curday)

Description

get Month Week

License

Apache License

Declaration

public static int getMonthWeek(String curday) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.*;

public class Main {
    static public SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    public static int getMonthWeek(String curday) {
        try {//from   w w  w . j a v a2s.c om
            java.util.Date date = str2date(curday);
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(date);
            return rightNow.get(Calendar.WEEK_OF_MONTH);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static Date str2date(String str) {
        Date result = null;
        try {
            Date udate = yyyyMMdd.parse(str);
            result = new Date(udate.getTime());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getTime(String parrten) {
        String timestr;
        if (parrten == null || parrten.equals("")) {
            parrten = "yyyyMMddHHmmss";
        }
        java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
        java.util.Date cday = new java.util.Date();
        timestr = sdf.format(cday);
        return timestr;
    }
}

Related

  1. getMonthLastDay()
  2. getMonthLastDay(String curmonth, int month)
  3. getMonthLastDay(String dateString)
  4. getMonthLastDay(String fmt)
  5. getMonthMaxDay(String sDate)
  6. getMonthWeek(String curday)
  7. getPreviosMonthFirstDay()
  8. getShortFirstDayOfMonth()
  9. getStringOfFirstDayInMonth()