Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert my date to timestamp in javascript

How to convert my date to timestamp i dont know where im doing wrong.Any suggestion please ?

var dates = '27-04-2015';
var date1 = new Date(dates).getTime();
alert(date1);
like image 900
Question User Avatar asked Aug 20 '26 11:08

Question User


1 Answers

Parameter you passed in the new Date('27-04-2015') is not valid. Use sepeartor '/' for change date format and send to the new Date('27/04/2015').

var dates = '27-04-2015';
var dates1 = dates.split("-");
var newDate = dates1[1]+"/"+dates1[0]+"/"+dates1[2];
alert(new Date(newDate).getTime());

Working Fiddle

like image 113
Sudharsan S Avatar answered Aug 22 '26 02:08

Sudharsan S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!