How to add 5 minutes to js date?

var days = 1;
var newDate = new Date(Date.now() + days * 24*60*60*1000);

document.write('Today: <em>');
document.write(new Date());
document.write('</em><br/> New: <strong>');
document.write(newDate);

Is make one day BUT i want 5 minutes how?

Thanks!

Well without Google I think is 1000 is a second the 60 is one hour? another 60 no idea and 24 a day?

Thanks!

http://jsfiddle.net/yzjb2qn9/1/

I get that I need to use .getMinutes to add extra value for date like one minute.

You have any idea this why not work

if (d > myDate)

d is current time mydate is set +1 minute untill disable button bit is stay enabled true why after d current time is greanter than set myDate plus 1 minute?

Thanks!

myDate is not a date?
var myDate = new Date();

How you think to convert with a built in function??

Thanks!

myDate = new Date();
myDate.setMinutes(myDate.getMinutes() + 1);

This is for set how many minutes need for still be disabled true? So extra time untill get current date is greater and to disable false? So can click?

Yes is get disabled true for one minute after current date is greater than myDate (when click button + one minute) then able to send again the button disabled false. I got crazy my mind with it :joy:

@camperextraordinaire This planned for able send one click event per 60 seconds. I not want the user click more than once just if try send it more then not able to do with disabled true. I think about it is something like a limit for click. Is not able to click like a robot have to wait :).

Thanks!

1 Like

I refactored your code to make it more readable and do what you intended to do.

$(document).ready(function() {
  function disableLikeButton() {
    $('#like').prop("disabled", true);
  }

  var localStorageDateString = localStorage.getItem('test');
  var currentDate = new Date();

  if (localStorageDateString) {
    var localStorageDate = new Date(localStorageDateString);
    if (localStorageDate.getTime() > currentDate.getTime()) {
      disableLikeButton();
    }
  }
  
  $('#like').click(function() {
    var currentDate = new Date();
    currentDate.setMinutes(currentDate.getMinutes() + 1);
    localStorage.setItem('test', currentDate);
    disableLikeButton();
  });
});
1 Like

Thank you so much! :joy: :joy: :joy: :joy: :joy: