React Suite DateRangePicker Date Time or Time
React Suite is a popular front-end UI framework that consisted of a set of React components that we can use in our react application. It is developer-friendly and supports the stable releases of all the modern browsers like Chrome, Edge, Firefox, Safari, etc. In this article, we will discuss React Suite DateRangePicker Date Time or Time.
The DateRangePicker component is used to take input of the date/time range from the user. By default, it takes only date range input but it can be configured to accept date-time range or just time range as input using the format property. This property takes a string as a value, which is the format of the date or time for the input.
React Suite DateRangePicker Date Time or Time Components:
- DateRangePicker: This component is used to take the input of the date range from the user.
React Suite DateRangePicker Date Time or Time Attributes/Props:
- format: This attribute is used to set the format of the input of the DateRangePicker component.
<DateRangePicker format="yyyy-MM-dd HH:mm:ss" />
Creating The React Application And Installing React Suite:
Step 1: Create the React application using the npx command:
npx create-react-app foldername
Step 2: After creating the project folder, move to it using the cd command:
Step 3: After creating the ReactJS application, Install the rsuite module so that we can use the DateRangePicker component using the following command:
npm install rsuite
Project Structure: After following the above steps, the project structure will look like this:
Let’s see some examples to understand how to use the React Suite DateRangePicker format attribute/prop.
Example 1: Now replace the code in the App.js file with the code below. In this example, we used the format attribute of the DateRangePicker component to set the format of the input to the date and time range.
Run the Application: Run your app using the following command from the root directory of the project.
Output: Go to http://localhost:3000/ in your browser to see the output.
Example 2: In this example, we used the format attribute of the DateRangePicker component to take only the time range as the input.