Convert dd-mm-yyyy string to date

后端 未结 14 2182
孤城傲影
孤城傲影 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:14

    In my case

    new Date("20151102034013".replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/, "$1-$2-$3T$4:$5:$6"))
    

    Result: Mon Nov 02 2015 04:40:13 GMT+0100 (CET) then I use .getTime() to work with milliseconds

提交回复
热议问题