简体   繁体   English

如何从JS中的日期选择器获取日期值(MM-DD-YYYY)

[英]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)当我从日期选择器中以这种格式输入值时(2020 年 3 月 24 日星期二 17:00:00 GMT-0800(PST),我需要将其转换为 (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:您可以使用momentjs并像这样格式化字符串:

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

Or if that's not an option, you can use Date object and use this solution .或者,如果这不是一个选项,您可以使用Date对象并使用此解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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