Code: Select all
var oldevent = new date(2012, 7, 2);
var today = new date;
document.write(today-oldevent);Moderator: General Moderators
Code: Select all
var oldevent = new date(2012, 7, 2);
var today = new date;
document.write(today-oldevent);Code: Select all
<script type="text/javascript">
//Set the two dates
var millennium =new Date(2000, 0, 1) //Month is 0-11 in JavaScript
today=new Date()
//Get 1 day in milliseconds
var one_day=1000*60*60*24
//Calculate difference btw the two dates, and convert to days
document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))+
" days has gone by since the millennium!")
</script>
Are you sure you want to use Math.ceil? That rounds upward.Vegan wrote:I guess I need to use a more conservative approach
Code: Select all
<script type="text/javascript"> //Set the two dates var millennium =new Date(2000, 0, 1) //Month is 0-11 in JavaScript today=new Date() //Get 1 day in milliseconds var one_day=1000*60*60*24 //Calculate difference btw the two dates, and convert to days document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))+ " days has gone by since the millennium!") </script>
Code: Select all
<script type='text/javascript'>
var millennium = new Date(2000, 0, 1);
var today = new Date();
var difference_ms = today - millennium;
var ms_in_a_day = 1000 * 60 * 60 * 24;
var difference_days = Math.round(difference_ms / ms_in_a_day);
document.write("Today is "+ difference_days + " days after the millennium.");
</script>No, Javascript should work the same, regardless of what OS the browser is running in. If your algorithm is correct, it will work.do I need to check to see if that function will work all the time, such as detect the OS in use?