Opening Calendar On The Specified Date
The currentDate prop allows you to open the calendar view directly to a specified date. This does not set the selected date, it only determines the initial calendar view.
For example, if you want the calendar to open to February 2021, you can set currentDate to a DateObject like this:
<DatePicker
currentDate={
new DateObject({
year: 2021,
month: 2,
day: 1
})
}
/>
Manually Set Year And Month In DatePicker
import React, { useState } from "react";
import DatePicker, { DateObject } from "react-multi-date-picker";
export default function Example() {
const [date, setDate] = useState(
new DateObject(),
);
function update(key, value) {
date[key] += value;
setDate(new DateObject(date));
}
const style = {
display: "inline-block",
width: "90px",
fontSize: "16px",
};
return (
<div style={{ textAlign: "center" }}>
<div>
<button onClick={() => update("month", 1)}>+</button>
<span style={style}>{date.month.name}</span>
<button onClick={() => update("month", -1)}>-</button>
</div>
<div>
<button onClick={() => update("year", 1)}>+</button>
<span style={style}>{date.year}</span>
<button onClick={() => update("year", -1)}>-</button>
</div>
<DatePicker
currentDate={date}
calendarPosition="bottom-center"
/>
</div>
)
}
Changing Start Day Of The Week
You can use the weekStartDayIndex property to change the start day of the week.
For example, if you want the start day of the week to be Monday, you should set the weekStartDayIndex value to 1.
The value of weekStartDayIndex must be a number between 0 and 6.
<DatePicker
weekStartDayIndex={1}
/>
Disabling Scroll Sensitivity
Using this prop sets the fixMainPosition value true while scrolling.
<DatePicker
scrollSensitive={false}
/>
Ignore Formatting
<DatePickers
format="Date:YYYY/MM/DD, Time:HH:mm:ss"
formattingIgnoreList={["Date", "Time"]}
plugins={[
<TimePicker position="bottom" />
]}
/>
Read Only Calendar
Both readOnly and disabled props prevent the user from selecting a new date, except that in readOnly mode, the calendar header remains active, but in disabled mode, the calendar header is also disabled.
<Calendar
value={[
new DateObject().toFirstOfWeek(),
new DateObject().toLastOfWeek(),
]}
range
readOnly
/>