I'm making a project with NextJs. Right now I'm making a page where the users are creating activities using useState and fetch POST. I think everything is working somewhat properly however I am having issues with the date.
When I try to post I get an error saying: "The JSON value could not be converted to System.DateTime".
I've come to understand that I need to post a date in accordance to ISO.
I have a date that I set with useState in a Textfield from MUI. I would like that date to be converted to ISO. I have tried different solutions but none have worked.
For further clarification this is what (parts of) my code looks like:
import {Textfield} from "@mui/material";
function CreateActivity {
var today = new Date();
var dd = String(today.getDate()).padStart(2, "0");
var mm = String(today.getMonth() + 1).padStart(2, "0");
var yyyy = today.getFullYear();
today = yyyy + "-" + mm + "-" + dd;
const [activityDate, setActivityDate] = useState(today + "T10:30");
return (
<div className={styles.textBox}>
<div>Date, time</div>
<TextField
variant="standard"
id="datetime-local"
type="datetime-local"
defaultValue={today + "T10:30"}
InputLabelProps={{
shrink: true,
}}
onChange={(event) => setActivityDate(event.target.value)}
/>
</div>
)
}