简体   繁体   中英

Need help on displaying readable date using javascript

I'm new to javascript and I've got this problem of showing dates.

I would like to display a readable date formatted like MM-DD-YYYY , but everytime I try to load the page, I always get an ASP format date.

Someone gave this code and I tried to use it on my project, yet, I still get the wrong format of date with this kind of error Uncaught TypeError: Cannot call method 'formatDate' of undefined .

What's wrong with this code?

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

I'm using C# MVC.

Might give this a try (assuming you're using jQuery... If I'm way off, I apologize):

// 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");
  });
});

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