计算自己从出生到现在过了多少天
<script>
/**
* 计算自己活了多少天
*/
//1)创建现在的日期对象,取出当前的毫秒值
var today = new Date();
var time = today.getTime();
//2)创建出生日期的时期对象,取出那时的毫秒值
var yestoday = new Date("1996/03/19");
var times = yestoday.getTime();
//3)两个毫秒值相减
var str = (time-times)/1000/3600/24;
document.write("张三已经过了<font color='red'>"+str+"</font>天了");
</script>
计算自己再活了多少天,能到100岁
<script>
/**
* 计算自己再活了多少天,能到100岁
*/
//1)创建现在的日期对象,取出当前的毫秒值
var today = new Date();
var time = today.getTime();
//2)创建将来日期的时间对象,取出那时的毫秒值
var yestoday = new Date(1996+100,3,19);
var times = yestoday.getTime();
//3)两个毫秒值相减
var str = (times-time)/1000/3600/24;
document.write("张三还差<font color='red'>"+str+"</font>天100岁");
</script>
求随机整数的公式 Math.random()*(max-min)+min