# CalendarConstraints.Builder

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/datepicker/CalendarConstraints.java)

*** ** * ** ***


```
public final class CalendarConstraints.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#build()()` Builds the `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints` object using the set parameters or defaults. |
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#setEnd(long)(long month)` A UTC timeInMilliseconds contained within the latest month the calendar will page to. |
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#setFirstDayOfWeek(int)(int firstDayOfWeek)` Sets what the first day of the week is; e.g., `Calendar.SUNDAY` in the U.S., `Calendar.MONDAY` in France. |
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#setOpenAt(long)(long month)` A UTC timeInMilliseconds contained within the month the calendar should openAt. |
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#setStart(long)(long month)` A UTC timeInMilliseconds contained within the earliest month the calendar will page to. |
| `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder` | `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.Builder#setValidator(com.google.android.material.datepicker.CalendarConstraints.DateValidator)(https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.DateValidator validator)` Limits valid dates to those for which `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.DateValidator#isValid(long)` is true. |

## Public constructors

### Builder

```
public Builder()
```

## Public methods

### build

```
public CalendarConstraints build()
```

Builds the `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints` object using the set parameters or defaults.

### setEnd

```
public CalendarConstraints.Builder setEnd(long month)
```

A UTC timeInMilliseconds contained within the latest month the calendar will page to. Defaults December, 2100.

If you have access to java.time in Java 8, you can obtain a long using `
java.time.ZonedDateTime`.

```
LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
```

If you don't have access to java.time in Java 8, you can obtain this value using a `
java.util.Calendar` instance from the UTC timezone.

```
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(year, month, 1);
c.getTimeInMillis();
```

### setFirstDayOfWeek

```
public CalendarConstraints.Builder setFirstDayOfWeek(int firstDayOfWeek)
```

Sets what the first day of the week is; e.g., `Calendar.SUNDAY` in the U.S., `Calendar.MONDAY` in France.

### setOpenAt

```
public CalendarConstraints.Builder setOpenAt(long month)
```

A UTC timeInMilliseconds contained within the month the calendar should openAt. Defaults to the month containing today if within bounds; otherwise, defaults to the starting month.

If you have access to java.time in Java 8, you can obtain a long using `
java.time.ZonedDateTime`.

```
LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
```

If you don't have access to java.time in Java 8, you can obtain this value using a `
java.util.Calendar` instance from the UTC timezone.

```
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(year, month, 1);
c.getTimeInMillis();
```

### setStart

```
public CalendarConstraints.Builder setStart(long month)
```

A UTC timeInMilliseconds contained within the earliest month the calendar will page to. Defaults January, 1900.

If you have access to java.time in Java 8, you can obtain a long using `
java.time.ZonedDateTime`.

```
LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
```

If you don't have access to java.time in Java 8, you can obtain this value using a `
java.util.Calendar` instance from the UTC timezone.

```
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(year, month, 1);
c.getTimeInMillis();
```

### setValidator

```
public CalendarConstraints.Builder setValidator(CalendarConstraints.DateValidator validator)
```

Limits valid dates to those for which `https://developer.android.com/reference/com/google/android/material/datepicker/CalendarConstraints.DateValidator#isValid(long)` is true. Defaults to all dates as valid.