Java Calendar Week getWeekdayPosition(Calendar jCalendar)

Here you can find the source of getWeekdayPosition(Calendar jCalendar)

Description

get Weekday Position

License

Open Source License

Declaration

public static int getWeekdayPosition(Calendar jCalendar) 

Method Source Code

//package com.java2s;
/**/*from w ww  .j  a  v  a2 s  . c  o m*/
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.util.Calendar;

public class Main {
    public static int getWeekdayPosition(Calendar jCalendar) {
        int weekOfMonth = jCalendar.get(Calendar.WEEK_OF_MONTH);

        Calendar firstDayJCalendar = (Calendar) jCalendar.clone();

        firstDayJCalendar.set(Calendar.DAY_OF_MONTH, 1);

        if (firstDayJCalendar.get(Calendar.DAY_OF_WEEK) > jCalendar.get(Calendar.DAY_OF_WEEK)) {

            return weekOfMonth - 1;
        }

        return weekOfMonth;
    }
}

Related

  1. getImmediateDayOfWeek(Calendar current, int dayOfWeek)
  2. getLastDayOfWeek(Calendar cal)
  3. getLastDayOfWeek(Calendar cal)
  4. getWeek(Calendar calendar)
  5. getWeekDay(Calendar cal)
  6. getWeekEnd(boolean startSunday, Calendar date)
  7. getWeekOfCurrentDayWithoutStartShift(Calendar cal)
  8. getWeekStart(boolean startSunday, Calendar date)
  9. isThisWeek(Calendar time)