0

I have a form and one button to plus some minutes to a time(hh:MM), but the time is a span tag.

At Firefox works well, but when I tested at Chrome doesn't work the Date(). What happened?

//Botão adicionar horário agenda.
$('.button').click(function() {
  var $duration_schedule = $('#duration');
  var duration = $duration_schedule.val(); // 30
  var hour = $('.time_schedule_form').text(); // 10:00
  var new_time = self.Plus_minutes(hour, duration);
  alert(new_time); // 10:30
});


Plus_minutes: function(hour, duration) {
    var time, new_hour, hours = '';
    time     = new Date("T"+hour); // Erro at Chrome
    time.setTime(time.getTime() + duration*60000);
    hours     = time.getHours().toString();
    minutes   = time.getMinutes().toString();
    if (minutes.length > 1) {
        new_hour = hours + ':' + minutes;
    } else {
        new_hour = hours + ':0' + minutes;
    }

    return new_hour;
},
Matheus Hahn
  • 17
  • 1
  • 7

3 Answers3

1

I suppose that it is happening because of constructor's input! In case of time you should put numbers in milliseconds. The Data Object have those constructors bellow:

  • new Date();
  • new Date(value);
  • new Date(dateString);
  • new Date(year, month[, date[, hours[, minutes[, seconds[,milliseconds]]]]]);

you can take at look at Developer.mozilla then you can check a better explanation about formats.

Maybe the Firefox are converting to including something in that part of code. I found out other explanation about Data input formats, you can take a look too at: Convert String to Date

Community
  • 1
  • 1
0

The correct format for UTC would be like 2013-02-27T17:00:00Z (Z is for Zulu Time). Append Z if not present to get correct UTC datetime string.

Waqas Ahmed
  • 185
  • 2
  • 11
0

You could achieve this using setMinutes to update using getMinutes.

newdate.setMinutes(newdate.getMinutes() + 10); 
Davor Mlinaric
  • 1,989
  • 1
  • 19
  • 26