Java Week getWeekNumByDate(String date)

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

Description

get Week Num By Date

License

Open Source License

Declaration

public static int getWeekNumByDate(String date) 

Method Source Code

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

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

public class Main {
    public static final String DF_YMD = "yyyy-MM-dd";

    public static int getWeekNumByDate(String date) {
        SimpleDateFormat format = new SimpleDateFormat(DF_YMD);
        try {//from w ww  . ja va  2  s  . c o  m
            Date d = format.parse(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int num = cal.get(Calendar.DAY_OF_WEEK) - 1;
            return num;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}

Related

  1. getWeekId(String date)
  2. getWeekInMonth()
  3. getWeekName()
  4. getWeekNumber(String sdate)
  5. getWeekNumberFromDate(String thedate)
  6. getWeekNumner(String date)
  7. getWeekOfMonth()
  8. getWeekStartDate(Integer weekNumber)
  9. isSameWeek(Date curDate, Date compareDate)