Home > Enterprise >  typescript - Is there a way to output the long date from datapicker
typescript - Is there a way to output the long date from datapicker

Time:03-10

In typescript, in this date-picker, after selecting a date from the calendar, the selected date is outputted in the format dd-mm-yy, is there a way to output the date in the long format(Wednesday 9th March 2022.) This is using the standard datepicker.

<input type="date" onChange={
(event:React.ChangeEvent<HTMLInputElement>) =>{
let newTimesheet = [...timesheet];
newTimesheet[index].date=event.target.value;
setTimesheet(newTimesheet);
}
}/>

CodePudding user response:

You can do this easily via Intl although the formatting is not the same as yours:

new Intl.DateTimeFormat("en-US", { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }).format(date); // Wednesday, March 9, 2022

Intl Documentation

CodePudding user response:

Try this:

setTimesheet(new Intl.DateTimeFormat('en-GB', { dateStyle: 'full' }).format(newTimesheet));

i hope it works!

  • Related