Java Week getWeek(SimpleDateFormat df, String dateStr)

Here you can find the source of getWeek(SimpleDateFormat df, String dateStr)

Description

get Week

License

Open Source License

Declaration

public static int getWeek(SimpleDateFormat df, String dateStr) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static int getWeek(SimpleDateFormat df, String dateStr) {
        Calendar c = Calendar.getInstance();
        try {/*from  w  w  w  . j  a v a 2s  .  c  o m*/
            c.setTime(df.parse(dateStr));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (0 == week) {
            week = 7;
        }
        return week;
    }

    public static Date parse(SimpleDateFormat df, String date) {
        try {
            return df.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. getThisWeek()
  2. getWeek()
  3. getWeek()
  4. getWeek(Date date)
  5. getWeek(int duration)
  6. getWeek(String date)
  7. getWeek(String pTime)
  8. getWeekAgo()
  9. getWeekBegin(Date date)