Java Calendar Create createCalendarInstance(final Locale locale)

Here you can find the source of createCalendarInstance(final Locale locale)

Description

Create a calendar instance that uses mondays or sundays as the first day of the week depending on the given locale and sets the week number 1 to the first week in the year that has four days of january.

License

Apache License

Parameter

Parameter Description
local the locale to define if a week starts on sunday or monday

Return

a calendar instance

Declaration

public static Calendar createCalendarInstance(final Locale locale) 

Method Source Code

//package com.java2s;
/**//  w  w  w.j  a v a  2  s  . c  o  m
 * OLAT - Online Learning and Training<br>
 * http://www.olat.org
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); <br>
 * you may not use this file except in compliance with the License.<br>
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing,<br>
 * software distributed under the License is distributed on an "AS IS" BASIS, <br>
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
 * See the License for the specific language governing permissions and <br>
 * limitations under the License.
 * <p>
 * Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
 * University of Zurich, Switzerland.
 * <p>
 */

import java.util.Calendar;

import java.util.Locale;

public class Main {
    /**
     * Create a calendar instance that uses mondays or sundays as the first day of the week depending on the given locale and sets the week number 1 to the first week in
     * the year that has four days of january.
     * 
     * @param local the locale to define if a week starts on sunday or monday
     * @return a calendar instance
     */
    public static Calendar createCalendarInstance(final Locale locale) {
        // use Calendar.getInstance(locale) that sets first day of week
        // according to locale or let user decide in GUI
        final Calendar cal = Calendar.getInstance(locale);
        // manually set min days to 4 as we are used to have it
        cal.setMinimalDaysInFirstWeek(4);
        return cal;
    }
}

Related

  1. createCalendar(int year, int month, int day)
  2. createCalendar(int year, int month, int day, int hour, int minute, int second, boolean ceiling)
  3. createCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second)
  4. createCalendar(long timeInMillis)
  5. createCalendarFromParts(String[] parts)
  6. createCalendarMidnight(final Date date)
  7. createCalendarWith()
  8. createDateFormatString(Calendar cal)
  9. createDateStr(Calendar calendar)