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!

First explain what you think each number above means or why do these numbers multiplied together multiplied by the days variable adds one day to the date?

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

Thanks!

How many hours are in a day?

How many minutes are in an hour?

How many seconds are in a minute?

How many milliseconds are in a second?

1 Like

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!

d has a type of Date. myDate is a string. You can not compare like that. You first need to convert myDate into a Date and then you could use the getTime method to compare both dates.

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

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

Thanks!

@design May I ask what is the purpose of the following inside the button click callback?

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

What is your ultimate goal here?

Inside the click callback function myDate is a Date. However, in the else code block, it is not. It is a string.

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?

So you want the user to be able to click the button again (the button would not be disabled) if more than one minute passed after each button click disables the button?

I was thinking the ultimate goal was to disable the Like button once it is clicked regardless of how much time has passed since the button was last clicked. Why would you want to let a user click Like more than once?

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:

@RandellDawson 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: