I got a query how do I convert yyyy-mm-dd hh:mm:ss to UNIX time-stamp using angularjs or JavaScript for example:2015-04-17 10:12:12this is how my date value how do i convert ??
3 Answers
You can try below snippet for unix timestamp...
var unixtimestamp = (new Date('2015-04-17 10:12:12')).getTime() / 1000;
Sorry my above solution was working fine in only Chrome.
Below soltution might help you..
var unixtimestamp = (new Date("2015-04-17 10:12:12".replace('-','/'))).getTime() / 1000;
alert(unixtimestamp);
jsfiddle link: http://jsfiddle.net/7r4c9Lqo/3/
1 Comment
Ashish Sapkale
Working js fiddle link, jsfiddle.net/7r4c9Lqo
You could do:
date1 = '2015-04-17 10:12:12'.split(':');
date2 = date1[0].split(' ');
date3 = date2[0].split('-');
the_date = new Date(parseInt(date3[0]),parseInt(date3[1])-1,parseInt(date3[2]),parseInt(date2[1]),parseInt(date1[1]),parseInt(date1[2]));
3 Comments
Raptor
this does not answer OP's question. The original date format is not like this
Raptor
ouch, that works, but it would be over-complicated. And
date3[1] is 04 (a string) ... forget to use parseInt() ?
+new Date('2015-04-17 10:12:12')- it will return a int valueDate.parse('2015-04-17 10:12:12')? See this