當前位置: 首頁>>代碼示例>>Java>>正文


Java Calendar.getFirstDayOfWeek方法代碼示例

本文整理匯總了Java中java.util.Calendar.getFirstDayOfWeek方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.getFirstDayOfWeek方法的具體用法?Java Calendar.getFirstDayOfWeek怎麽用?Java Calendar.getFirstDayOfWeek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.getFirstDayOfWeek方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getStartAndEndDateForWeek

import java.util.Calendar; //導入方法依賴的package包/類
protected static Map<String, Object> getStartAndEndDateForWeek(String period) {
  Map<String, Object> dateMap = new HashMap<>();
  Map<String, Integer> periodMap = getDaysByPeriodStr(period);
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
  int firstDayOfWeek = calendar.getFirstDayOfWeek();        
  calendar.add(Calendar.DATE, -(calendar.get(Calendar.DAY_OF_WEEK)-firstDayOfWeek));
  calendar.add(Calendar.WEEK_OF_YEAR, 1);
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  String endDateStr = sdf.format(calendar.getTime());
  dateMap.put(endDate, endDateStr);
  dateMap.put(endTimeMilis, calendar.getTimeInMillis());
  calendar.add(periodMap.get(KEY), -(periodMap.get(VALUE)));
  calendar.add(Calendar.DATE, 1);
  calendar.set(Calendar.HOUR_OF_DAY,0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  dateMap.put(INTERVAL, "1w");
  dateMap.put(FORMAT, "yyyy-ww");
  String startDateStr = sdf.format(calendar.getTime());
  dateMap.put(startDate, startDateStr);
  dateMap.put(startTimeMilis, calendar.getTimeInMillis());
  return dateMap;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-lms-mw,代碼行數:26,代碼來源:BaseMetricsActor.java

示例2: getCurrentMonthCalendar

import java.util.Calendar; //導入方法依賴的package包/類
public static ArrayList<Calendar> getCurrentMonthCalendar(Calendar c, int offset) {
    ArrayList<Calendar> calendars = new ArrayList<>();
    Calendar currentMonth = (Calendar) c.clone();
    currentMonth.add(Calendar.MONTH, offset);


    Calendar cal = (Calendar) c.clone();
    cal.add(Calendar.MONTH, offset);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    int off = cal.getFirstDayOfWeek() - firstDayOfWeek;
    if (off > 0) {
        off -= 7;
    }
    cal.add(Calendar.DATE, off);

    while ((cal.get(MONTH) < currentMonth.get(Calendar.MONTH) + 1 || cal.get(YEAR) < currentMonth.get(Calendar.YEAR)) //
            && cal.get(YEAR) <= currentMonth.get(Calendar.YEAR)) {
        for (int i = 0; i < 7; i++) {
            calendars.add((Calendar) cal.clone());
            cal.add(Calendar.DATE, 1);
            Log.i("aaa", cal.get(Calendar.MONTH) + "--" + cal.get(Calendar.DAY_OF_MONTH));
        }
    }
    return calendars;
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:27,代碼來源:CommonUtils.java

示例3: main

import java.util.Calendar; //導入方法依賴的package包/類
public static void main(String[] args) {
    Calendar huCalendar = Calendar.getInstance(new Locale("hu","HU"));
    int hufirstDayOfWeek = huCalendar.getFirstDayOfWeek();
    if (hufirstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }

    Calendar ukCalendar = Calendar.getInstance(new Locale("uk","UA"));
    int ukfirstDayOfWeek = ukCalendar.getFirstDayOfWeek();
    if (ukfirstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:Bug4527203.java

示例4: DashboardAdapter

import java.util.Calendar; //導入方法依賴的package包/類
public DashboardAdapter(Context context) {
    Calendar calendar = Calendar.getInstance();
    int today = calendar.get(Calendar.DAY_OF_WEEK);

    // Today is default
    rowItems.add(new Section(context.getString(R.string.section_title_today), getSectionDate(calendar)));
    calendar.add(Calendar.DAY_OF_YEAR, 1);

    if (today >= Calendar.MONDAY && today <= Calendar.WEDNESDAY) {
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        rowItems.add(new Section(context.getString(R.string.section_title_this_week), getSectionDate(calendar)));
    } else if (today == Calendar.THURSDAY) {
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
    } else if (today == Calendar.FRIDAY)
        rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
    else if (today == Calendar.SATURDAY)
        rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));

    calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    if (calendar.getFirstDayOfWeek() != Calendar.SUNDAY || today != Calendar.SUNDAY)
        calendar.add(Calendar.WEEK_OF_YEAR, 1);

    rowItems.add(new Section(context.getString(R.string.section_title_next_week), getSectionDate(calendar)));

    // TODO: Holiday and interval sections (between two holidays, to give a clearer overview over whats happening in the long run)
    calendar.add(Calendar.WEEK_OF_YEAR, 1);
    rowItems.add(new Section("Until the end of the universe", getSectionDate(calendar)));

    // TODO: Listen on login
    UserInfo userInfo = FirebaseAuth.getInstance().getCurrentUser();
    if (userInfo != null) {
        DocumentReference userReference = FirebaseFirestore.getInstance()
                .collection("users")
                .document(userInfo.getUid());

        userReference.collection("groups")
                .addSnapshotListener(this);
        userReference.collection("items")
                .addSnapshotListener(new GroupItemsChangeListener(FirebaseAuth.getInstance().getCurrentUser().getUid()));
    }
}
 
開發者ID:whirlwind-studios,項目名稱:School1-Android,代碼行數:47,代碼來源:DashboardAdapter.java

示例5: test

import java.util.Calendar; //導入方法依賴的package包/類
@Test
public void test() throws DatatypeConfigurationException {
    XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1970, 1, 1, 0, 0, 0, 0, 0);
    GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
    int firstDayOfWeek = calendar.getFirstDayOfWeek();
    Calendar defaultCalendar = Calendar.getInstance();
    int defaultFirstDayOfWeek = defaultCalendar.getFirstDayOfWeek();
    if (firstDayOfWeek != defaultFirstDayOfWeek) {
        Assert.fail("Failed firstDayOfWeek=" + firstDayOfWeek + " != defaultFirstDayOfWeek=" + defaultFirstDayOfWeek);
    } else {
        System.out.println("Success firstDayOfWeek=" + firstDayOfWeek + " == defaultFirstDayOfWeek=" + defaultFirstDayOfWeek);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:Bug7042647Test.java

示例6: getWeekEnd

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 得到當前周截止時間
 *
 * @param date
 * @return
 */
public static Date getWeekEnd(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	calendar.get(Calendar.WEEK_OF_YEAR);
	int firstDay = calendar.getFirstDayOfWeek();
	calendar.set(Calendar.DAY_OF_WEEK, 8 - firstDay);
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 59);
	calendar.set(Calendar.SECOND, 59);
	calendar.set(Calendar.MILLISECOND, 0);
	return calendar.getTime();
}
 
開發者ID:xubinux,項目名稱:xbin-store,代碼行數:19,代碼來源:DateUtils.java

示例7: execute

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public Object execute(List<ExpressionData<?>> dataList, Context context,Cell currentCell) {
	Calendar c = buildCalendar(dataList);
	int weekDay=c.get(Calendar.DAY_OF_WEEK);
	boolean isFirstSunday = (c.getFirstDayOfWeek() == Calendar.SUNDAY);
	if(isFirstSunday){
		weekDay = weekDay - 1;
		if(weekDay == 0){
			weekDay = 7;
		}
	}
	switch(weekDay){
	case 1:
		return "星期一";
	case 2:
		return "星期二";
	case 3:
		return "星期三";
	case 4:
		return "星期四";
	case 5:
		return "星期五";
	case 6:
		return "星期六";
	case 7:
		return "星期日";
	}
	throw new ReportComputeException("Unknow week day :"+weekDay);
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:30,代碼來源:WeekFunction.java

示例8: getWeekEnd

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 得到當前周截止時間
 * 
 * @param date
 * @return
 */
public static Date getWeekEnd(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	calendar.get(Calendar.WEEK_OF_YEAR);
	int firstDay = calendar.getFirstDayOfWeek();
	calendar.set(Calendar.DAY_OF_WEEK, 8 - firstDay);
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 59);
	calendar.set(Calendar.SECOND, 59);
	calendar.set(Calendar.MILLISECOND, 0);
	return calendar.getTime();
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:19,代碼來源:DateUtils.java

示例9: Test4143951

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * @bug 4143951
 * Russian first day of week should be Monday. Confirmed.
 */
public void Test4143951() {
    Calendar cal = Calendar.getInstance(new Locale("ru", "", ""));
    if (cal.getFirstDayOfWeek() != Calendar.MONDAY) {
        errln("Fail: First day of week in Russia should be Monday");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:LocaleTest.java

示例10: getWeekIndex

import java.util.Calendar; //導入方法依賴的package包/類
/**
 *
 * @param weekIndex
 * @param calendar
 * @return
 */
public static int getWeekIndex(int weekIndex, Calendar calendar) {
    int firstDayWeekPosition = calendar.getFirstDayOfWeek();
    if (firstDayWeekPosition == 1) {
        return weekIndex;
    } else {
        if (weekIndex == 1) {
            return 7;
        } else {
            return weekIndex - 1;
        }
    }
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:19,代碼來源:CalendarUtility.java

示例11: create

import java.util.Calendar; //導入方法依賴的package包/類
public static MonthView create(ViewGroup parent, LayoutInflater inflater,
                               DateFormat weekdayNameFormat, Listener listener, Calendar today, int dividerColor,
                               int dayBackgroundResId, int dayTextColorResId, int titleTextColor, boolean displayHeader,
                               int headerTextColor, List<CalendarCellDecorator> decorators, Locale locale,
                               DayViewAdapter adapter) {
  final MonthView view = (MonthView) inflater.inflate(R.layout.month, parent, false);
  view.setDayViewAdapter(adapter);
  view.setDividerColor(dividerColor);
  view.setDayTextColor(dayTextColorResId);
  view.setTitleTextColor(titleTextColor);
  view.setDisplayHeader(displayHeader);
  view.setHeaderTextColor(headerTextColor);

  if (dayBackgroundResId != 0) {
    view.setDayBackground(dayBackgroundResId);
  }

  final int originalDayOfWeek = today.get(Calendar.DAY_OF_WEEK);

  view.isRtl = isRtl(locale);
  view.locale = locale;
  int firstDayOfWeek = today.getFirstDayOfWeek();
  final CalendarRowView headerRow = (CalendarRowView) view.grid.getChildAt(0);
  for (int offset = 0; offset < 7; offset++) {
    today.set(Calendar.DAY_OF_WEEK, getDayOfWeek(firstDayOfWeek, offset, view.isRtl));
    final TextView textView = (TextView) headerRow.getChildAt(offset);
    textView.setText(weekdayNameFormat.format(today.getTime()));
  }
  today.set(Calendar.DAY_OF_WEEK, originalDayOfWeek);
  view.listener = listener;
  view.decorators = decorators;
  return view;
}
 
開發者ID:savvisingh,項目名稱:DateRangePickerLibrary,代碼行數:34,代碼來源:MonthView.java

示例12: establish

import java.util.Calendar; //導入方法依賴的package包/類
Calendar establish(Calendar cal) {
    boolean weekDate = isSet(WEEK_YEAR)
                        && field[WEEK_YEAR] > field[YEAR];
    if (weekDate && !cal.isWeekDateSupported()) {
        // Use YEAR instead
        if (!isSet(YEAR)) {
            set(YEAR, field[MAX_FIELD + WEEK_YEAR]);
        }
        weekDate = false;
    }

    cal.clear();
    // Set the fields from the min stamp to the max stamp so that
    // the field resolution works in the Calendar.
    for (int stamp = MINIMUM_USER_STAMP; stamp < nextStamp; stamp++) {
        for (int index = 0; index <= maxFieldIndex; index++) {
            if (field[index] == stamp) {
                cal.set(index, field[MAX_FIELD + index]);
                break;
            }
        }
    }

    if (weekDate) {
        int weekOfYear = isSet(WEEK_OF_YEAR) ? field[MAX_FIELD + WEEK_OF_YEAR] : 1;
        int dayOfWeek = isSet(DAY_OF_WEEK) ?
                            field[MAX_FIELD + DAY_OF_WEEK] : cal.getFirstDayOfWeek();
        if (!isValidDayOfWeek(dayOfWeek) && cal.isLenient()) {
            if (dayOfWeek >= 8) {
                dayOfWeek--;
                weekOfYear += dayOfWeek / 7;
                dayOfWeek = (dayOfWeek % 7) + 1;
            } else {
                while (dayOfWeek <= 0) {
                    dayOfWeek += 7;
                    weekOfYear--;
                }
            }
            dayOfWeek = toCalendarDayOfWeek(dayOfWeek);
        }
        cal.setWeekDate(field[MAX_FIELD + WEEK_YEAR], weekOfYear, dayOfWeek);
    }
    return cal;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:45,代碼來源:CalendarBuilder.java

示例13: main

import java.util.Calendar; //導入方法依賴的package包/類
public static void main(String[] args) {
    Calendar czechCalendar = Calendar.getInstance(new Locale("cs"));
    int firstDayOfWeek = czechCalendar.getFirstDayOfWeek();
    if (firstDayOfWeek != Calendar.MONDAY) {
        throw new RuntimeException();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:Bug4302966.java

示例14: getMonthCells

import java.util.Calendar; //導入方法依賴的package包/類
List<List<MonthCellDescriptor>> getMonthCells(MonthDescriptor month, Calendar startCal) {
  Calendar cal = Calendar.getInstance(timeZone, locale);
  cal.setTime(startCal.getTime());
  List<List<MonthCellDescriptor>> cells = new ArrayList<>();
  cal.set(DAY_OF_MONTH, 1);
  int firstDayOfWeek = cal.get(DAY_OF_WEEK);
  int offset = cal.getFirstDayOfWeek() - firstDayOfWeek;
  if (offset > 0) {
    offset -= 7;
  }
  cal.add(Calendar.DATE, offset);

  Calendar minSelectedCal = minDate(selectedCals);
  Calendar maxSelectedCal = maxDate(selectedCals);

  while ((cal.get(MONTH) < month.getMonth() + 1 || cal.get(YEAR) < month.getYear()) //
      && cal.get(YEAR) <= month.getYear()) {
    Logr.d("Building week row starting at %s", cal.getTime());
    List<MonthCellDescriptor> weekCells = new ArrayList<>();
    cells.add(weekCells);
    for (int c = 0; c < 7; c++) {
      Date date = cal.getTime();
      boolean isCurrentMonth = cal.get(MONTH) == month.getMonth();
      boolean isSelected = isCurrentMonth && containsDate(selectedCals, cal);
      boolean isSelectable =
          isCurrentMonth && betweenDates(cal, minCal, maxCal) && isDateSelectable(date);
      boolean isToday = sameDate(cal, today);
      boolean isHighlighted = containsDate(highlightedCals, cal);
      int value = cal.get(DAY_OF_MONTH);

      RangeState rangeState = RangeState.NONE;
      if (selectedCals.size() > 1) {
        if (sameDate(minSelectedCal, cal)) {
          rangeState = RangeState.FIRST;
        } else if (sameDate(maxDate(selectedCals), cal)) {
          rangeState = RangeState.LAST;
        } else if (betweenDates(cal, minSelectedCal, maxSelectedCal)) {
          rangeState = RangeState.MIDDLE;
        }
      }

      weekCells.add(
          new MonthCellDescriptor(date, isCurrentMonth, isSelectable, isSelected, isToday,
              isHighlighted, value, rangeState));
      cal.add(DATE, 1);
    }
  }
  return cells;
}
 
開發者ID:savvisingh,項目名稱:DateRangePicker,代碼行數:50,代碼來源:CalendarPickerView.java

示例15: updateDays

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Updates the days.
 */
private void updateDays() {
    Calendar calendar = (Calendar) calendarView.getCalendar().clone();

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    // Set the calendar to the first day of the current month.
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    int month = calendar.get(Calendar.MONTH);

    // Set the calendar to the end of the previous month.
    while (calendar.getFirstDayOfWeek() != calendar.get(Calendar.DAY_OF_WEEK)) {
        calendar.add(Calendar.DAY_OF_MONTH, -1);
    }

    boolean firstLoop = true;

    // Ignore the week day row and the week number column
    for (int i = numberOfDaysPerWeek + (calendarView.getShowWeeks() ? 1 : 0); i < getChildren().size(); i++) {

        // If we are in the first column and if we want to show the weeks, set them.
        if (i % (numberOfDaysPerWeek + 1) == 0 && calendarView.getShowWeeks()) {
            Label label = (Label) getChildren().get(i);
            label.setText(Integer.toString(calendar.get(Calendar.WEEK_OF_YEAR)));
        } else {

            DateCell dateCell = (DateCell) getChildren().get(i);

            boolean disabled = normalizedMaxDate.get() != null && calendar.getTime().after(normalizedMaxDate.get())
                    || normalizedMinDate.get() != null && calendar.getTime().before(normalizedMinDate.get());

            dateCell.setDisable(disabled);

            dateCell.updateInRange(calendar.get(Calendar.MONTH) == month);
            dateCell.setItem(calendar.getTime());
            dateCell.requestLayout();
            if (firstLoop) {
                firstLoop = false;
            }

            calendar.add(Calendar.DATE, 1);
        }
    }
}
 
開發者ID:scourgemancer,項目名稱:graphing-loan-analyzer,代碼行數:51,代碼來源:CalendarViewSkin.java


注:本文中的java.util.Calendar.getFirstDayOfWeek方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。