Reputation: 311
<script>
var tdt= new Date();
t=tdt.getFullYear()+"-"+(tdt.getMonth()+1)+"-"+tdt.getDate() // 2015-04-17
var tody = new Date(t).getTime(); /* 1429209000000 */
document.write(tody);
<script>
When I execute this code in Mozilla Firefox, I get 'NaN', but when I execute this code in Google Chrome, I get '1429209000000'. Does anyone know how to get the value '1429209000000' to be printed when I execute in Firefox and Opera?
Upvotes: 2
Views: 77
Reputation: 1038
Just use slashes as separators.
var tdt= new Date();
t=tdt.getFullYear()+"/"+(tdt.getMonth()+1)+"/"+tdt.getDate() // 2015-04-17
var tody = new Date(t).getTime(); /* 1429209000000 */
document.write(tody);
Upvotes: 3