Condividi tramite


TemporalAdjusters.DayOfWeekInMonth(Int32, DayOfWeek) Method

Definition

Returns the day-of-week in month adjuster, which returns a new date with the ordinal day-of-week based on the month.

[Android.Runtime.Register("dayOfWeekInMonth", "(ILjava/time/DayOfWeek;)Ljava/time/temporal/TemporalAdjuster;", "", ApiSince=26)]
public static Java.Time.Temporal.ITemporalAdjuster? DayOfWeekInMonth (int ordinal, Java.Time.DayOfWeek? dayOfWeek);
[<Android.Runtime.Register("dayOfWeekInMonth", "(ILjava/time/DayOfWeek;)Ljava/time/temporal/TemporalAdjuster;", "", ApiSince=26)>]
static member DayOfWeekInMonth : int * Java.Time.DayOfWeek -> Java.Time.Temporal.ITemporalAdjuster

Parameters

ordinal
Int32

the week within the month, unbounded but typically from -5 to 5

dayOfWeek
DayOfWeek

the day-of-week, not null

Returns

the day-of-week in month adjuster, not null

Attributes

Remarks

Returns the day-of-week in month adjuster, which returns a new date with the ordinal day-of-week based on the month. This is used for expressions like the 'second Tuesday in March'.

The ISO calendar system behaves as follows:<br> The input 2011-12-15 for (1,TUESDAY) will return 2011-12-06.<br> The input 2011-12-15 for (2,TUESDAY) will return 2011-12-13.<br> The input 2011-12-15 for (3,TUESDAY) will return 2011-12-20.<br> The input 2011-12-15 for (4,TUESDAY) will return 2011-12-27.<br> The input 2011-12-15 for (5,TUESDAY) will return 2012-01-03.<br> The input 2011-12-15 for (-1,TUESDAY) will return 2011-12-27 (last in month).<br> The input 2011-12-15 for (-4,TUESDAY) will return 2011-12-06 (3 weeks before last in month).<br> The input 2011-12-15 for (-5,TUESDAY) will return 2011-11-29 (4 weeks before last in month).<br> The input 2011-12-15 for (0,TUESDAY) will return 2011-11-29 (last in previous month).<br>

For a positive or zero ordinal, the algorithm is equivalent to finding the first day-of-week that matches within the month and then adding a number of weeks to it. For a negative ordinal, the algorithm is equivalent to finding the last day-of-week that matches within the month and then subtracting a number of weeks to it. The ordinal number of weeks is not validated and is interpreted leniently according to this algorithm. This definition means that an ordinal of zero finds the last matching day-of-week in the previous month.

The behavior is suitable for use with most calendar systems. It uses the DAY_OF_WEEK and DAY_OF_MONTH fields and the DAYS unit, and assumes a seven day week.

Java documentation for java.time.temporal.TemporalAdjusters.dayOfWeekInMonth(int, java.time.DayOfWeek).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to