Java Week getWeekNumber(String sdate)

Here you can find the source of getWeekNumber(String sdate)

Description

get Week Number

License

Open Source License

Declaration

public static int getWeekNumber(String sdate) 

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 getWeekNumber(String sdate) {
        Date date = strToDate(sdate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);/*from www . java  2  s.c  o  m*/
        return c.get(Calendar.DAY_OF_WEEK);
    }

    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. getWeekFirst(String format)
  2. getWeekFromDate(String dateString)
  3. getWeekId(String date)
  4. getWeekInMonth()
  5. getWeekName()
  6. getWeekNumberFromDate(String thedate)
  7. getWeekNumByDate(String date)
  8. getWeekNumner(String date)
  9. getWeekOfMonth()