2013-07-28 38 views
0

我是JavaScript新手,我有这个显示日期的问题。需要帮助显示可读日期使用javascript

我想显示格式为MM-DD-YYYY的可读日期,但每次尝试加载页面时,我都会得到一个ASP格式日期。

有人给出了这段代码,我试图在我的项目中使用它,但我仍然得到错误的日期格式与这种错误Uncaught TypeError: Cannot call method 'formatDate' of undefined

这段代码有什么问题?

$(document).ready(function() { 
var date = $.datepicker.formatDate('yy-mm-dd', new Date($("#dateOfBirth").val())); 
$("#dateOfBirth").val(date); 
}); 

我正在使用C#MVC。

+0

是否使用'' ?如果是这样,则必须使用“YYYY-MM-DD”格式作为值。 –

回答

0

也许这给一个尝试(假设你使用jQuery ......如果我的路要走,我道歉):

// You might not need the next two lines... 
// And if not, just delete them as well as the last line 
jQuery.noConflict(); 
jQuery(function($) { 
    $(document).ready(function() { 
    $("#dateOfBirth").datepicker(); 
    $("#dateOfBirth").datepicker("dateFormat", "yy-mm-dd"); 
    }); 
});