本文整理了Java中java.util.Calendar.getFirstDayOfWeek()
方法的一些代码示例,展示了Calendar.getFirstDayOfWeek()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getFirstDayOfWeek()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getFirstDayOfWeek
[英]Returns the first day of the week for this Calendar.
[中]
代码示例来源:origin: stackoverflow.com
// get today and clear time of day
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
// get start of this week in milliseconds
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
System.out.println("Start of this week: " + cal.getTime());
System.out.println("... in milliseconds: " + cal.getTimeInMillis());
// start of the next week
cal.add(Calendar.WEEK_OF_YEAR, 1);
System.out.println("Start of the next week: " + cal.getTime());
System.out.println("... in milliseconds: " + cal.getTimeInMillis());
代码示例来源:origin: camunda/camunda-bpm-platform
public static long computeStartOfNextWeek(long now) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.WEEK_OF_YEAR, 1);
return cal.getTime().getTime();
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
/**
* Method setDtStart
*/
public void setDtStart(Calendar start) {
int oldStart = 0;
if (dtStart != null) {
oldStart = dtStart.getFirstDayOfWeek();
}
else {
oldStart = Calendar.MONDAY;
}
if (start == null) {
dtStart = CalendarFactoryUtil.getCalendar(
TimeZoneUtil.getTimeZone(StringPool.UTC));
dtStart.setTime(new Date(0L));
}
else {
dtStart = (Calendar)start.clone();
dtStart.clear(Calendar.ZONE_OFFSET);
dtStart.clear(Calendar.DST_OFFSET);
dtStart.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC));
}
dtStart.setMinimalDaysInFirstWeek(4);
dtStart.setFirstDayOfWeek(oldStart);
dtStart.set(Calendar.SECOND, 0);
dtStart.set(Calendar.MILLISECOND, 0);
}
代码示例来源:origin: lcw2004/one
public static Date getFirstDayOfWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
}
代码示例来源:origin: i2p/i2p.i2p
break;
case MINUTE:
calendar.set(Calendar.SECOND, 0);
calendar.add(Calendar.MINUTE, -(calendar.get(Calendar.MINUTE) % timeUnitCount));
break;
case HOUR:
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.add(Calendar.HOUR_OF_DAY, -(calendar.get(Calendar.HOUR_OF_DAY) % timeUnitCount));
break;
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
int diffDays = calendar.get(Calendar.DAY_OF_WEEK) - calendar.getFirstDayOfWeek();
if (diffDays < 0) {
diffDays += 7;
代码示例来源:origin: iSoron/uhabits
/**
* @return array with week days numbers starting according to locale
* settings, e.g. [2,3,4,5,6,7,1] in Europe
*/
public static Integer[] getLocaleWeekdayList()
{
Integer[] dayNumbers = new Integer[7];
Calendar calendar = new GregorianCalendar();
calendar.set(DAY_OF_WEEK, calendar.getFirstDayOfWeek());
for (int i = 0; i < dayNumbers.length; i++)
{
dayNumbers[i] = calendar.get(DAY_OF_WEEK);
calendar.add(DAY_OF_MONTH, 1);
}
return dayNumbers;
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
myCurrent.setTimeZone(TimeZoneUtil.getTimeZone(StringPool.UTC));
myCurrent.setMinimalDaysInFirstWeek(4);
myCurrent.setFirstDayOfWeek(dtStart.getFirstDayOfWeek());
myCurrent.set(Calendar.SECOND, 0);
myCurrent.set(Calendar.MILLISECOND, 0);
代码示例来源:origin: lcw2004/one
public static Date getLastDayOfWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek() + 6);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
}
代码示例来源:origin: camunda/camunda-bpm-platform
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.MINUTE, 1);
break;
case DailyRollingFileAppender.TOP_OF_HOUR:
this.set(Calendar.MINUTE, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
break;
case DailyRollingFileAppender.TOP_OF_WEEK:
this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek());
this.set(Calendar.HOUR_OF_DAY, 0);
this.set(Calendar.SECOND, 0);
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getThisWeekStartTime() {
Calendar today = Calendar.getInstance();
today.set(7, today.getFirstDayOfWeek());
Calendar weekFirstDay = Calendar.getInstance();
weekFirstDay.clear();
weekFirstDay.set(1, today.get(1));
weekFirstDay.set(2, today.get(2));
weekFirstDay.set(5, today.get(5));
return weekFirstDay.getTime();
}
代码示例来源:origin: KylinOLAP/Kylin
cal.setTime(temp);
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
代码示例来源:origin: jenkinsci/jenkins
@Override
void setTo(Calendar c, int i) {
int v = i-offset;
int was = c.get(field);
c.set(field,v);
final int firstDayOfWeek = c.getFirstDayOfWeek();
if (v < firstDayOfWeek && was >= firstDayOfWeek) {
// in crontab, the first DoW is always Sunday, but in Java, it can be Monday or in theory arbitrary other days.
// When first DoW is 1/2 Monday, calendar points to 1/2 Monday, setting the DoW to Sunday makes
// the calendar moves forward to 1/8 Sunday, instead of 1/1 Sunday. So we need to compensate that effect here.
addTo(c,-7);
} else if (was < firstDayOfWeek && firstDayOfWeek <= v) {
// If we wrap the other way around, we need to adjust in the opposite direction of above.
addTo(c, 7);
}
}
};
代码示例来源:origin: KylinOLAP/Kylin
cal.setTime(temp);
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
// set the date
Calendar cal = Calendar.getInstance();
cal.set(2011, 10 - 1, 12);
// "calculate" the start date of the week
Calendar first = (Calendar) cal.clone();
first.add(Calendar.DAY_OF_WEEK,
first.getFirstDayOfWeek() - first.get(Calendar.DAY_OF_WEEK));
// and add six days to the end date
Calendar last = (Calendar) first.clone();
last.add(Calendar.DAY_OF_YEAR, 6);
// print the result
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(first.getTime()) + " -> " +
df.format(last.getTime()));
}
代码示例来源:origin: ch.qos.logback/core
public static long computeStartOfNextWeek(long now) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.WEEK_OF_YEAR, 1);
return cal.getTime().getTime();
}
代码示例来源:origin: iSoron/uhabits
/**
* @return array with weekday names starting according to locale settings,
* e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Germany
*/
public static String[] getLocaleDayNames(int format)
{
String[] days = new String[7];
Calendar calendar = new GregorianCalendar();
calendar.set(DAY_OF_WEEK, calendar.getFirstDayOfWeek());
for (int i = 0; i < days.length; i++)
{
days[i] = calendar.getDisplayName(DAY_OF_WEEK, format,
getLocale());
calendar.add(DAY_OF_MONTH, 1);
}
return days;
}
代码示例来源:origin: com.hynnet/logback-core
public static long computeStartOfNextWeek(long now) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.WEEK_OF_YEAR, 1);
return cal.getTime().getTime();
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
mWeekStart = weekStart;
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/ch.qos.logback.core
public static long computeStartOfNextWeek(long now) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.WEEK_OF_YEAR, 1);
return cal.getTime().getTime();
}
代码示例来源:origin: wangdan/AisenWeiBo
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
内容来源于网络,如有侵权,请联系作者删除!