1

i got one more problem if any one have any solution please help me. Ploblem is like this I want to convert milliseconds into minutes in javascript and then decrement minutes by 60000 milliseconds untill it reaches current time for which i am using this code:-

<?php
$date2   = date('Y-m-d H:i:s');
$currentdate = strtotime($date2);
$targetdate = strtotime('2012-05-09 21:30:00');
?>
<script type=text/javascript>
var currentdate = <?php echo $currentdate; ?>;
var targetdate = <?php echo $targetdate; ?>;
var difference = targetdate - currentdate;

var minutes = Math.floor(difference / 60);
var i = minutes;
var intID;
function decrementMin() {
    if(i==0)
    {
        clearInterval(intID);
        alert('Minute = Congratulation your time begin!');
    }
    if(i>=0){
    document.getElementById('minutes').innerHTML = i + "minutes";
    i--;
    }
}
decrementMin();
intID = setInterval('decrementMin()', 60000);
</script>

The problem is like that their are total 478 seconds and when we convert it into minutes then it become 7.9666 but by using Math.floor() it show's 7 minutes and give alert before .9666 second means before 58 seconds. If any one have any solution please help me i am waiting for your answer please.

Sanjay Singh
  • 363
  • 2
  • 10
  • 1
    Why are you doing half of the work in PHP and the other half in JavaScript? – John Conde May 09 '12 at 16:00
  • as i have already use currentdate and targetdate in php so i don't want to convert it again so i have taken it from php code. – Sanjay Singh May 09 '12 at 16:04
  • For one thing, you have a `i+"minutes`. If this is your real code - you should take out the quotation marks. – JNF May 10 '12 at 06:14
  • Another - why `document.getElementById('minutes').innerHTML = i + "minutes;` and not `innerHTML = i`? – JNF May 10 '12 at 06:27
  • @JNF i m using document.getElementById('minutes').innerHTML = i + "minutes"; for printing the value of i in a particular div only. – Sanjay Singh May 11 '12 at 12:00

1 Answers1

0

.9666 minutes isn't 9666 seconds - it's 58 seconds

JNF
  • 3,696
  • 3
  • 31
  • 64