当前位置: 首页>>代码示例>>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;未经允许,请勿转载。