编写一个函数,将格式为M/D/YYYY的用户输入日期转换为API所需的格式(YYYYMMDD).参数" userDate"和返回值是字符串.
例如,它应将用户输入的日期"12/31/2014"转换为适用于API的"20141231".
function formatDate(userDate)
{
userDate = new Date();
y = userDate.getFullYear();
m = userDate.getMonth();
d = userDate.getDate();
return y + m + d;
}
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题吗?
无法通过在线测试.
javascript ×1