本文整理了Java中org.joda.time.LocalDate.withDayOfWeek()
方法的一些代码示例,展示了LocalDate.withDayOfWeek()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.withDayOfWeek()
方法的具体详情如下:
包路径:org.joda.time.LocalDate
类名称:LocalDate
方法名:withDayOfWeek
[英]Returns a copy of this date with the day of week field updated.
LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of week changed.
[中]返回此日期的副本,其中“星期几”字段已更新。
LocalDate是不可变的,因此没有set方法。相反,此方法返回一个新实例,其值为“星期几”已更改。
代码示例来源:origin: stackoverflow.com
LocalDate now = new LocalDate();
System.out.println(now.withDayOfWeek(DateTimeConstants.MONDAY)); //prints 2011-01-17
System.out.println(now.withDayOfWeek(DateTimeConstants.SUNDAY)); //prints 2011-01-23
代码示例来源:origin: stackoverflow.com
// TODO: Consider time zones, calendars etc
LocalDate now = new LocalDate();
LocalDate monday = now.withDayOfWeek(DateTimeConstants.MONDAY);
System.out.println(monday);
代码示例来源:origin: stackoverflow.com
LocalDate date = new LocalDate();
date = date.withDayOfWeek(2);
System.out.println(DateTimeFormat.forPattern("EEEE").print(date));
代码示例来源:origin: stackoverflow.com
LocalDate date = new LocalDate();
date = date.withDayOfWeek(2);
System.out.println(date.dayOfWeek().getAsText());
代码示例来源:origin: nl.cloudfarming.client/calendar-api
public static DateBounds getWeekBounds(LocalDate actualDate) {
LocalDate lowBound = actualDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate hiBound = actualDate.withDayOfWeek(DateTimeConstants.SUNDAY);
return new DateBounds(lowBound, hiBound);
}
代码示例来源:origin: stackoverflow.com
LocalDate now = new LocalDate();
System.out.println( now.withDayOfWeek(DateTimeConstants.MONDAY) );
System.out.println( now.withDayOfWeek(DateTimeConstants.SUNDAY) );
代码示例来源:origin: maxyou/CalendarPicker
public static CalendarWeek getWeekIncludeThisDay(LocalDate localDate) {
LocalDate monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate tuesday = localDate.withDayOfWeek(DateTimeConstants.TUESDAY);
LocalDate wednesday = localDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);
LocalDate thursday = localDate.withDayOfWeek(DateTimeConstants.THURSDAY);
LocalDate friday = localDate.withDayOfWeek(DateTimeConstants.FRIDAY);
LocalDate saturday = localDate.withDayOfWeek(DateTimeConstants.SATURDAY);
LocalDate sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY);
CalendarWeek calendarWeek = new CalendarWeek(
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
);
calendarWeek.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
calendarWeek.originDate = localDate;
return calendarWeek;
}
代码示例来源:origin: stackoverflow.com
date = date.withDayOfWeek( i + 1 ); // Add one to transform index into ordinal.
System.out.println( "There were " + days.get( i ) + " dates on " + date.dayOfWeek().getAsText() );
代码示例来源:origin: fluxtream/fluxtream-app
public static LocalDate getBeginningOfWeek(final int year, final int week) {
return (new LocalDate())
.withWeekyear(year)
.withWeekOfWeekyear(week)
.minusWeeks(1)
.withDayOfWeek(FIRST_DAY_OF_WEEK);
// Need to subtract 1 week because Sunday is the last day of the week, which
// would logically move all the week start dates forward by 6 days. Better
// one day earlier than JodaTime's standard than 6 days later than
// users' expectations.
}
代码示例来源:origin: org.motechproject/motech-platform-commons-date
public static List<DayOfWeek> daysStarting(DayOfWeek day, int numberOfDays) {
List<DayOfWeek> days = new ArrayList<>();
for (int i = 0; i <= numberOfDays; i++) {
days.add(getDayOfWeek(DateUtil.today().withDayOfWeek(day.getValue()).plusDays(i)));
}
return days;
}
}
代码示例来源:origin: com.cronutils/htime
@VisibleForTesting
Map<String, String> initDaysOfWeek(Locale locale) {
String fullDoW =
String.format("%s%s%s%s",
constants.dayOfWeekName(), constants.dayOfWeekName(),
constants.dayOfWeekName(), constants.dayOfWeekName()
);
LocalDate date = new LocalDate();
Map<String, String> mapping = Maps.newHashMap();
for (int j = 1; j < 8; j++) {
String dow = date.withDayOfWeek(j).dayOfWeek().getAsText(locale).toLowerCase();
mapping.put(dow, fullDoW);
mapping.put(dow.substring(0, 3), constants.dayOfWeekName());
}
return mapping;
}
代码示例来源:origin: com.synaptix/SynaptixWidget
private void init() {
LocalDate firstDate = new LocalDate(year, month, 1);
startDate = firstDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate lastDate = firstDate.withDayOfMonth(firstDate.dayOfMonth().getMaximumValue());
LocalDate endDate;
if (lastDate.getDayOfWeek() != DateTimeConstants.SUNDAY) {
endDate = lastDate.withDayOfWeek(DateTimeConstants.SUNDAY);
} else {
endDate = lastDate;
}
Duration d = new Duration(startDate.toDateMidnight(DateTimeZone.UTC), endDate.toDateMidnight(DateTimeZone.UTC));
nbWeek = ((int) d.getStandardDays() + 1) / 7;
}
代码示例来源:origin: yannecer/NCalendar
public static LocalDate getSunFirstDayOfWeek(LocalDate date) {
if (date.dayOfWeek().get() == 7) {
return date;
} else {
return date.minusWeeks(1).withDayOfWeek(7);
}
}
代码示例来源:origin: fluxtream/fluxtream-app
public void setWeekTimeUnit() {
LocalDate origFromDate = fromDate;
timeUnit = TimeUnit.WEEK;
fromDate = new LocalDate(fromDate.getYear(), fromDate.getMonthOfYear(), fromDate.getDayOfMonth())
.withDayOfWeek(TimeUtils.FIRST_DAY_OF_WEEK);
// Unfortunately, the above code returns the following week instead of the containing week for
// every day other than Sunday. Check for this and decrement the week if needed.
if(fromDate.isAfter(origFromDate)) {
fromDate = fromDate.minusWeeks(1);
}
}
}
代码示例来源:origin: ManyDesigns/Portofino
public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) {
logger.debug("Initializing month");
this.referenceDateTime = referenceDateTime;
logger.debug("Reference date time: {}", referenceDateTime);
this.firstDayOfWeek = firstDayOfWeek;
logger.debug("First day of week: {}", firstDayOfWeek);
referenceDateMidnight = new LocalDate(referenceDateTime);
referenceYear = referenceDateTime.getYear();
referenceMonth = referenceDateTime.getMonthOfYear();
monthStart = referenceDateMidnight.withDayOfMonth(1);
monthEnd = monthStart.plusMonths(1);
monthInterval = new Interval(monthStart.toDateTimeAtStartOfDay(), monthEnd.toDateTimeAtStartOfDay());
monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek);
monthViewEnd = monthViewStart.plusWeeks(6);
monthViewInterval = new Interval(monthViewStart.toDateTimeAtStartOfDay(), monthViewEnd.toDateTimeAtStartOfDay());
logger.debug("Month view start: {}", monthViewStart);
logger.debug("Initializing weeks");
weeks = createWeeksArray(6);
LocalDate weekStart = monthViewStart;
for (int i = 0; i < weeks.length; i++) {
LocalDate weekEnd = weekStart.plusWeeks(1);
weeks[i] = createWeek(weekStart, weekEnd);
weekStart = weekEnd;
}
}
代码示例来源:origin: net.objectlab.kit/datecalc-joda
/**
* Assumes that the month is correct, get the day for the 2rd wednesday.
*
* @param original
* the start date
* @return the 3rd Wednesday of the month
*/
private LocalDate calculate3rdWednesday(final LocalDate original) {
final LocalDate firstOfMonth = original.withDayOfMonth(1);
LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
if (firstWed.isBefore(firstOfMonth)) {
firstWed = firstWed.plusWeeks(1);
}
return firstWed.plusWeeks(2);
}
代码示例来源:origin: Appendium/objectlabkit
/**
* Assumes that the month is correct, get the day for the 2rd wednesday.
*
* @param original
* the start date
* @return the 3rd Wednesday of the month
*/
private LocalDate calculate3rdWednesday(final LocalDate original) {
final LocalDate firstOfMonth = original.withDayOfMonth(1);
LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
if (firstWed.isBefore(firstOfMonth)) {
firstWed = firstWed.plusWeeks(1);
}
return firstWed.plusWeeks(2);
}
代码示例来源:origin: com.manydesigns/portofino-calendar
public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) {
logger.debug("Initializing month");
this.referenceDateTime = referenceDateTime;
logger.debug("Reference date time: {}", referenceDateTime);
this.firstDayOfWeek = firstDayOfWeek;
logger.debug("First day of week: {}", firstDayOfWeek);
referenceDateMidnight = new LocalDate(referenceDateTime);
referenceYear = referenceDateTime.getYear();
referenceMonth = referenceDateTime.getMonthOfYear();
monthStart = referenceDateMidnight.withDayOfMonth(1);
monthEnd = monthStart.plusMonths(1);
monthInterval = new Interval(monthStart.toDateTimeAtStartOfDay(), monthEnd.toDateTimeAtStartOfDay());
monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek);
monthViewEnd = monthViewStart.plusWeeks(6);
monthViewInterval = new Interval(monthViewStart.toDateTimeAtStartOfDay(), monthViewEnd.toDateTimeAtStartOfDay());
logger.debug("Month view start: {}", monthViewStart);
logger.debug("Initializing weeks");
weeks = createWeeksArray(6);
LocalDate weekStart = monthViewStart;
for (int i = 0; i < weeks.length; i++) {
LocalDate weekEnd = weekStart.plusWeeks(1);
weeks[i] = createWeek(weekStart, weekEnd);
weekStart = weekEnd;
}
}
内容来源于网络,如有侵权,请联系作者删除!