Parse Date String to Date in JavaScript

后端 未结 3 1886
挽巷
挽巷 2021-01-27 03:57

I have this date string \"2013:05:12 11:41:31\"

I tried:

var strDate = \"2013:05:12 11:41:31\";
var dateParts = strDate.split(\":\");

var date = new Da         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-27 04:20

    var strDate = "2013:05:12 11:41:31";
    var dateParts = strDate.split(" ");
    dateParts = dateParts[0];
    dateParts = dateParts.split(":");
    
    var date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
    
    alert(date);
    

    First get the date, then split it and then put it in the date object.

提交回复
热议问题