Java Week getWeekNumner(String date)

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

Description

get Week Numner

License

Open Source License

Declaration

public static Integer getWeekNumner(String date) 

Method Source Code


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

import java.text.DateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Integer getWeekNumner(String date) {

        Integer weekNumber = 0;/*  w ww  . j  a va  2s .c o  m*/

        try {
            if (date.equals("")) {
                return weekNumber;
            }

            DateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
            Date passedDate = formatter.parse(date);

            Calendar cal = Calendar.getInstance();
            cal.setTime(passedDate);
            weekNumber = cal.get(Calendar.WEEK_OF_YEAR);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Error While fetching week number for " + date);
        }
        return weekNumber;
    }
}

Related

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