Example usage for java.util Calendar setFirstDayOfWeek

List of usage examples for java.util Calendar setFirstDayOfWeek

Introduction

In this page you can find the example usage for java.util Calendar setFirstDayOfWeek.

Prototype

public void setFirstDayOfWeek(int value) 

Source Link

Document

Sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // print current first day of the week
    int day = cal.getFirstDayOfWeek();
    System.out.println("Current first day of the week:" + day);

    // set first day of the week as something else
    cal.setFirstDayOfWeek(Calendar.WEDNESDAY);

    // print altered first day of the week
    day = cal.getFirstDayOfWeek();//from ww  w.java2 s .co m
    ;
    System.out.println("Altered first day of the week:" + day);
}

From source file:Main.java

public static int getWeekOfYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setTime(date);/*from  ww w. ja v  a 2s . c  o m*/
    int week = c.get(Calendar.WEEK_OF_YEAR) - 1;
    week = week == 0 ? 52 : week;
    return week > 0 ? week : 1;
}

From source file:Main.java

public static ArrayList<String> getCurrentWeek() {
    SimpleDateFormat format = new SimpleDateFormat("dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    ArrayList<String> days = new ArrayList<String>();
    for (int i = 0; i < 7; i++) {
        days.add(format.format(calendar.getTime()));
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }//from  w ww . j  a v a  2 s  .  co m
    return days;
}

From source file:Main.java

public static Calendar calendar() {
    Calendar cal = GregorianCalendar.getInstance(Locale.CHINESE);
    cal.setFirstDayOfWeek(Calendar.MONDAY);
    return cal;//from   w w  w  .ja v  a 2s.c  om
}

From source file:Main.java

/**
 *
 * @param context/*from   w  w w.j  a  v  a 2  s.c  o  m*/
 * @param firstDayOfWeek
 * @return
 */
public static Calendar getTodayCalendar(Context context, int firstDayOfWeek) {
    Calendar currentCalendar = Calendar.getInstance(context.getResources().getConfiguration().locale);
    currentCalendar.setFirstDayOfWeek(firstDayOfWeek);

    return currentCalendar;
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

/**
 * /*from  w  w  w.  j  ava  2s  .c o m*/
 * @param date
 * @return array of two date elements, first is the first day of week, and
 *         the second is the end week date
 */
public static Date[] getBounceDateofWeek(Date date) {
    Calendar calendar = new GregorianCalendar();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(date);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Date begin = calendar.getTime();

    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    Date end = calendar.getTime();
    return new Date[] { begin, end };
}

From source file:jp.classmethod.aws.brian.job.BrianQuartzJobBean.java

static SimpleDateFormat createFormat() {
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan")); // TODO localize
    calendar.setMinimalDaysInFirstWeek(4);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTimeInMillis(0);/*from   ww  w.  ja v  a  2 s.  co  m*/
    format.setCalendar(calendar);
    return format;
}

From source file:com.hurence.logisland.utils.DateUtils.java

/**
 * Compute the week number of parameter date
 *
 * @param date/* ww w. j a  v a  2s.c om*/
 * @return Week number : ex 13
 */
public static int getWeekNumberFromDate(Date date) {

    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);

        return calendar.get(Calendar.WEEK_OF_YEAR);
    } else {
        return 0;
    }
}

From source file:com.hurence.logisland.utils.DateUtils.java

/**
 * Check if the date parameter occurs during a weekend.
 *
 * @return Current time in ISO-8601 format, e.g. : "2012-07-03T07:59:09.206 UTC"
 */// w  w  w .  j  av a 2 s .  c  o m
public static boolean isWeekend(Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
        return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
    } else {
        return false;
    }

}

From source file:com.hurence.logisland.utils.DateUtils.java

/**
 * Check if the date parameter is within a given range of hours
 *
 * @return true or false//from w w w  . j a v a 2 s.c  o  m
 */
public static boolean isWithinHourRange(Date date, int startHour, int stopHour) {
    if (stopHour < startHour) {
        throw new IllegalArgumentException("start hour shall be before stop hour");
    }

    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int currentHour = calendar.get(Calendar.HOUR_OF_DAY);

        return currentHour >= startHour && currentHour <= stopHour;
    } else {
        return false;
    }

}