The Date object has various methods for creating a date as string in special formats.
Few of them are below:
toDateString() – Fri Sep 22 2023,
toLocaleDateString() – 22/09/2023,
toString() – Fri Sep 22 2023 19:11:23 GMT+0530 (India Standard Time) and so on.
import React, { useState } from "react";
export default function App() {
const [date, setDate] = useState(new Date());
return <p>Date: {date.toDateString()}</p>;
}
// Result
// Date: Fri Sep 22 2023
Work with our skilled React developers to accelerate your project and boost its performance.
Hire Reactjs Developers