Home > Blockchain >  how to change input date format
how to change input date format

Time:12-13

I have a input field which is date. It looks like this output image i got

It was showing dd/mm/yyyy in UI. But my need was yyyy/mm/dd. It should show yyyy/mm/dd instead of dd/mm/yyyy

Code I tried:

export default function App() {
const onDateChange = (dateValue) =>{
console.log(dateValue)
}
return (
<div>
<input onChange = {(e)=>{onDateChange(e.target.value)} } type="date" format='yyyy/mm/dd' />
</div>
);
}

My need was yyyy/mm/dd. It should show yyyy/mm/dd instead of dd/mm/yyyy I tried searching stackoverflow. Some answers shows, it changes depends upon the locale. But I need it to be yyyy/mm/dd everytime fixed. I tried a lot. But cant find solutions. Please help me with some solutions

CodePudding user response:

For a better experience with dates, I'd recommend you to use the day.js library, it's quite small but very useful, in it you can find an option to format your dates as you wish e.g. dayjs().format(YYYY-MM-DD)

Hope it works for you

CodePudding user response:

To set and get the input type date in dd-mm-yyyy format we will use type attribute. The type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

  • Related