JavaScript how to calcuate seconds left in the current minute of the time

I want to update a clock in the UI when the time changes from 12:01 to 12:02.

I can do a setInterval every 60 seconds, but the beginning might not be on the first second of a new minute. How can I ensure that it starts at the first second?

I think I need to find out how many seconds are left in the current minute and then do a setTimeout that fires setInterval when the seconds elapse.

var secondsLeft = ?; //calculate seconds left in this minute

setTimeout(function(){
    setInterval(function(){
        //update clock
    }, 1000 * 60);
}, secondsLeft);

If moment.js makes it easier, that's fine with me.

Answer:1

Try this: secondsLeft = 60 - new Date().getSeconds()

Answer:2

Using the following code: params = { Bucket: 'bucket.com', Key: zipPath }, s3 = new AWS.S3(); params.Body = zipFile; s3.putObject(params, function(err, data) { if (err) { ...

Using the following code: params = { Bucket: 'bucket.com', Key: zipPath }, s3 = new AWS.S3(); params.Body = zipFile; s3.putObject(params, function(err, data) { if (err) { ...

  1. upload file amazon s3 javascript
  2. upload file amazon s3 java
  3. upload file amazon s3 android
  4. upload file amazon s3 c#
  5. upload file amazon s3
  6. upload file amazon s3 command line
  7. upload file amazon s3 using php
  8. upload file amazon cloud drive
  9. upload amazon file
  10. upload file to amazon s3 codeigniter
  11. upload file to amazon s3 node js
  12. upload file to amazon workspace
  13. upload file to amazon s3 laravel
  14. upload file to amazon s3 bucket c#
  15. upload file to amazon s3 php
  16. upload file to amazon ec2
  17. upload file to amazon ec2 instance
  18. upload file to amazon s3 python
  19. upload flat file amazon
  20. upload file to amazon kindle

I am starting to use Ractive and I would like to understand better how to make reusable components. It is quite easy to write a generic widget that can be used in different situations. My problem is ...

I am starting to use Ractive and I would like to understand better how to make reusable components. It is quite easy to write a generic widget that can be used in different situations. My problem is ...

I'm trying to write a lightbox that shows an image inside a container when a div is being clicked. Said div has the actual image to be displayed as a background image, working as a thumbnail. These ...

I'm trying to write a lightbox that shows an image inside a container when a div is being clicked. Said div has the actual image to be displayed as a background image, working as a thumbnail. These ...

  1. getting client side value in code behind

can anyone tell me why this is not working? ui = (function() { collabElement = document.getElementById( 'approveCollab' ); if(collabElement) collabElement.onclick = function(){editor....

can anyone tell me why this is not working? ui = (function() { collabElement = document.getElementById( 'approveCollab' ); if(collabElement) collabElement.onclick = function(){editor....