Convert dd-mm-yyyy string to date

后端 未结 14 1911
孤城傲影
孤城傲影 2020-11-22 05:09

i am trying to convert a string in the format dd-mm-yyyy into a date object in JavaScript using the following:

 var from = $(\"#datepicker\").val();
 var to          


        
14条回答
  •  抹茶落季
    2020-11-22 06:06

    Another possibility:

    var from = "10-11-2011"; 
    var numbers = from.match(/\d+/g); 
    var date = new Date(numbers[2], numbers[0]-1, numbers[1]);
    

    Match the digits and reorder them

提交回复
热议问题