Get date value from input element

Hi to all
I have this input element:

<input type="date" id="label_1" />

And i want to get the date value that i have inside this and convert it into timestamp.
I tried with the following code but something is going wrong:

var date1=$('#label_1').val();
date1=new Date(date1);
console.log(date1);

The console outputs “Invalid Date”. The date that i had choose was the 1 Feb 2017.How i can retrieve the date value and convert this into timestamp?

var d = new Date('1 Feb 2017');

var myDate = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " +
  d.getHours() + ":" + d.getMinutes();

myDate = myDate.split("-");
var newDate = myDate[1] + "/" + myDate[0] + "/" + myDate[2];
alert(new Date(newDate).getTime());
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.