简体   繁体   中英

how to get date value as (MM-DD-YYYY) from date picker in JS

When I pick the value from the date picker input its in this format (Tue Mar 24 2020 17:00:00 GMT-0800(PST) I need to convert it to (MM-DD-YYYY)

Here is the part from my code where I get the value of the date

Reportinfo.ProjectDate = document.getElementById("date").value;

Any Ideas ? I didn't know how to implement

"toLocaleDateString()"  

You can use momentjs and format the string like this:

moment(date).format('MM-DD-YYYY');

Or if that's not an option, you can use Date object and use this solution .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM