문제

I have a date string "17/02/2013" that I would like to convert to a js date object formatted @dd-mm-yy but don't know how. Any suggestions? and i need to set this date as minDate in datepicker

My JQuery Code :

   var time_value = result.sdate;
   var values = time_value.split("/");
   var parsed_date = new Date(values[2], values[1], values[0]);
                   $('.datepicker').datepicker({
                       minDate: parsed_date
                   }); 
   alert(parsed_date);

In alert message

    Mon Mar 17 2014 00:00:00 GMT+0530 (India Standard Time)
도움이 되었습니까?

해결책

You don't need a new Date object. You have to replace the / with - in your string because your date format (dd mm yyyy) is already correct. Only the seperator for minDate is wrong.

var time_value = result.sdate;
var parsed_date = time_value.replace(/\//g, '-');
                $('.datepicker').datepicker({
                    minDate: parsed_date
                }); 
alert(parsed_date);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top