当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.setFirstDayOfWeek方法代码示例

本文整理汇总了Java中java.util.Calendar.setFirstDayOfWeek方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.setFirstDayOfWeek方法的具体用法?Java Calendar.setFirstDayOfWeek怎么用?Java Calendar.setFirstDayOfWeek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.setFirstDayOfWeek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: format

import java.util.Calendar; //导入方法依赖的package包/类
@Override
public String format(DateTime timestamp) {
    Calendar c = Calendar.getInstance(timestamp.getZone().toTimeZone(), LOCALE);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(4);
    c.setTimeInMillis(timestamp.getMillis());

    int week = c.get(Calendar.WEEK_OF_YEAR);
    int weekYear = c.getWeekYear();
    int year = c.get(Calendar.YEAR);
    if (weekYear < year) {
        // get weeks from last year
        c.add(Calendar.DAY_OF_MONTH, -7);
        week = c.getWeeksInWeekYear();
    }
    return zeroPadded(2, String.valueOf(week));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TimestampFormatter.java

示例2: getWeekDayOfYear

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 一周的日期
 * @param date  时间
 * @return  结果
 */
public static List<Date> getWeekDayOfYear(Date date) {
    Calendar calendar = getCalendarFromDate(date);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setMinimalDaysInFirstWeek(DAYS_OF_A_WEEK);
    int week = calendar.get(Calendar.WEEK_OF_YEAR);
    int year = calendar.get(Calendar.YEAR);

    List<Date> result = new ArrayList<Date>();
    result.add(getDateOfYearWeek(year, week, Calendar.MONDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.TUESDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.WEDNESDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.THURSDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.FRIDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.SATURDAY));
    result.add(getDateOfYearWeek(year, week, Calendar.SUNDAY));
    return result;
}
 
开发者ID:1991wangliang,项目名称:lorne_core,代码行数:23,代码来源:DateUtil.java

示例3: convertToMonday

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 将日期转为当周的星期一,返回getTime()的long值
 * @param time Date
 * @return long
 * @throws ParseException
 */
private static long convertToMonday(Date time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 设置时间格式
    Calendar cal = Calendar.getInstance();
    cal.setTime(time);
    // 判断要计算的日期是否是周日,如果是则减一天计算周六的,否则会出问题,计算到下一周去了
    int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
    if (1 == dayWeek) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }
    cal.setFirstDayOfWeek(Calendar.MONDAY);// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
    int day = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
    cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
    String imptimeBegin = sdf.format(cal.getTime());	//所在周星期一的日期
    return sdf.parse(imptimeBegin).getTime();
}
 
开发者ID:WeGdufe,项目名称:MovingGdufe-Android,代码行数:22,代码来源:TimeUtils.java

示例4: setCalendarParameters

import java.util.Calendar; //导入方法依赖的package包/类
void setCalendarParameters() {
	int d = 1;

	Calendar cal = _date.getCalendar();

	if (Configuration.get("FIRST_DAY_OF_WEEK").equals("mon")) {
		cal.setFirstDayOfWeek(Calendar.MONDAY);
		d = 2;
	} else
		cal.setFirstDayOfWeek(Calendar.SUNDAY);

	cal.set(Calendar.DAY_OF_MONTH, 1);
	cal.getTime();
	firstDay = cal.get(Calendar.DAY_OF_WEEK) - d;
	if (firstDay == -1)
		firstDay = 6;
	daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
 
开发者ID:ser316asu,项目名称:Dahlem_SER316,代码行数:19,代码来源:JNCalendar.java

示例5: getAllWeeks

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 返回该年有多少个自然周
 * 
 * @param year
 *            最多53 一般52 如果12月月末今天在本年53周(属于第二年第一周) 那么按照当年52周算
 * @return
 */
public static int getAllWeeks(String year) {
	Calendar calendar = Calendar.getInstance();
	SimpleDateFormat sdf = getTimeFormatYMD();
	try {
		calendar.setTime(sdf.parse(year + "-12-31"));
	} catch (ParseException e) {
		e.printStackTrace();
	}
	calendar.setFirstDayOfWeek(Calendar.MONDAY);
	int week = calendar.get(Calendar.WEEK_OF_YEAR);
	if (week != 53) {
		week = 52;
	}
	return week;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:23,代码来源:DateUtils.java

示例6: setWeekAsSelected

import java.util.Calendar; //导入方法依赖的package包/类
public void setWeekAsSelected(Date currentDate) {
    final Calendar currentCalendar = CalendarUtility.getTodayCalendar(mContext, mFirstDayOfWeek);
    currentCalendar.setFirstDayOfWeek(mFirstDayOfWeek);
    currentCalendar.setTime(currentDate);

    // Clear previous marks
    clearWeekOfTheMonthStyle(mLastSelectedDay);

    // Store current values as last values
    setLastSelectedDay(currentDate);

    List<DayView> views = findWeekViewsByCalendar(currentCalendar);
    for (DayView view : views) {
        view.setBackgroundColor(mSelectedDayBackground);
    }
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:17,代码来源:CalendarView.java

示例7: getCurrentWeekDay

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 本周指定星期几的日期
 *
 * @param date  指定的日期
 * @param day   那一天
 * @return  结果
 */
public static String getCurrentWeekDay(Date date, int day) {
    Calendar calendar = getCalendarFromDate(date);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setMinimalDaysInFirstWeek(DAYS_OF_A_WEEK);
    int week = calendar.get(Calendar.WEEK_OF_YEAR);
    int year = calendar.get(Calendar.YEAR);

    return formatDate(getDateOfYearWeek(year, week, day));
}
 
开发者ID:1991wangliang,项目名称:lorne_core,代码行数:17,代码来源:DateUtil.java

示例8: getWeek

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 返回月的第几周
 * @param day
 * @return
 */
public static String getWeek(String day) {
    String[] ymd = day.split(Constants.MIDDLE_LINE);
    SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDD);
    Date date = null;
    try {
        date = sdf.parse(day);
    } catch (ParseException e) {
        return Constants.EMPTY_STR;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(date);
    int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
    return ymd[0] + Constants.MIDDLE_LINE + ymd[1] + Constants.COLON + weekOfMonth;
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:22,代码来源:DateUtil.java

示例9: getWeekOfYear

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 取得当前日期是多少周
 * 
 * @param date
 * @return
 */
public static int getWeekOfYear(Date date)
{
    Calendar c = new GregorianCalendar();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(7);
    c.setTime(date);
    
    return c.get(Calendar.WEEK_OF_YEAR);
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:16,代码来源:MIP_DateUtil.java

示例10: Test4080631

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 4080631: Calendar.hashCode is amazingly bad
 */
public void Test4080631() {
    Calendar cal = Calendar.getInstance();
    int h1 = cal.hashCode();
    cal.add(SECOND, +1);
    int h2 = cal.hashCode();
    Calendar cal2 = (Calendar) cal.clone();
    cal.add(MILLISECOND, +1);
    int h3 = cal.hashCode();
    logln("hash code: h1=" + h1 + ", h2=" + h2 + ", h3=" + h3);
    if (h1 == h2 || h1 == h3 || h2 == h3) {
        errln("hash code is poor: hashCode=" + h1);
    }
    h2 = cal2.hashCode();
    cal.add(MILLISECOND, -1);
    int h4 = cal.hashCode();
    logln("hash code: h2=" + h2 + ", h4=" + h4);
    if (cal.equals(cal2) && h2 != h4) {
        errln("broken hash code: h2=" + h2 + ", h4=" + h4);
    }
    int x = cal.getFirstDayOfWeek() + 3;
    if (x > SATURDAY) {
        x -= 7;
    }
    cal.setFirstDayOfWeek(x);
    int h5 = cal.hashCode();
    logln("hash code: h4=" + h4 + ", h5=" + h5);
    if (h4 == h5) {
        errln("has code is poor with first day of week param: hashCode=" + h4);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:CalendarRegression.java

示例11: getWeekCountBasedOnMode

import java.util.Calendar; //导入方法依赖的package包/类
private int getWeekCountBasedOnMode() {
    int weekCount = calendarMode.visibleWeeksCount;
    boolean isInMonthsMode = calendarMode.equals(CalendarMode.MONTHS);
    if (isInMonthsMode && mDynamicHeightEnabled && adapter != null && pager != null) {
        Calendar cal = (Calendar) adapter.getItem(pager.getCurrentItem()).getCalendar().clone();
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        //noinspection ResourceType
        cal.setFirstDayOfWeek(getFirstDayOfWeek());
        weekCount = cal.get(Calendar.WEEK_OF_MONTH);
    }
    return weekCount + DAY_NAMES_ROW;
}
 
开发者ID:ptrstovka,项目名称:calendarview2,代码行数:13,代码来源:CalendarView2.java

示例12: getFirstDayOfMonth

import java.util.Calendar; //导入方法依赖的package包/类
public static Date getFirstDayOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.set(Calendar.DAY_OF_MONTH, ONE);
    return calendar.getTime();
}
 
开发者ID:Wangsu-Cloud-Storage,项目名称:wcs-android-sdk,代码行数:8,代码来源:DateUtil.java

示例13: getWeekOfYear

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 获取当前时间为每年第几周
 *
 * @param date
 * @return
 */
public static int getWeekOfYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setTime(date);
    int week = c.get(Calendar.WEEK_OF_YEAR) - 1;
    week = week == 0 ? 52 : week;
    return week > 0 ? week : 1;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:15,代码来源:StringUtils.java

示例14: getEndOfWeek

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Converts the given time to a time in the current time zone representing
 * the end of the week. It is assumed that weeks always start on MONDAY
 * independently of the server locale.
 * 
 * @param baseTime
 *            time in milliseconds to be converted
 * @return Calendar representing the end of the week based on the given
 *         baseTime
 */
public static Calendar getEndOfWeek(long baseTime) {
    final Calendar cal = getCalendar(baseTime);
    cal.setFirstDayOfWeek(Calendar.MONDAY);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    return cal;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:DateConverter.java

示例15: clearWeekOfTheMonthStyle

import java.util.Calendar; //导入方法依赖的package包/类
private void clearWeekOfTheMonthStyle(Date currentDate) {
        if (currentDate != null) {
            final Calendar calendar = CalendarUtility.getTodayCalendar(mContext, mFirstDayOfWeek);
            calendar.setFirstDayOfWeek(mFirstDayOfWeek);
            calendar.setTime(currentDate);

//            final List<DayView> weekViews = findWeekViewsByCalendar(calendar);
//            for (DayView weekView : weekViews) {
//                weekView.setBackgroundColor(mCalendarBackgroundColor);
//
//                mIsCommonDay = true;
//                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
//                if (totalDayOfWeekend().length != 0) {
//                    for (int weekend : totalDayOfWeekend()) {
//                        if (calendar.get(Calendar.DAY_OF_WEEK) == weekend) {
//                            weekView.setTextColor(mWeekendColor);
//                            mIsCommonDay = false;
//                        }
//                    }
//                }
//
//                if (mIsCommonDay) {
//                    weekView.setTextColor(mDayOfWeekTextColor);
//                }
//            }

            final List<DayView> views = findWeekViewsByCalendar(calendar);
            for (DayView view : views) {
                view.setBackgroundColor(mCalendarBackgroundColor);
            }
        }
    }
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:33,代码来源:CalendarView.java


注:本文中的java.util.Calendar.setFirstDayOfWeek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。