1

I am using a jQuery plugin named mobiscroll to select a date, but the problem is that I also need to add to the result plus 15 minutes.

I have a function p(j), which returns 08/28/2012 12:15 - 12:15 (or only 08/28/2012 12:15 - as convenient), but instead i need 12:15 - 12:30. Are there any ideas?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
NoNameZ
  • 785
  • 4
  • 14
  • 22

4 Answers4

1

What about string manipulation?

var dateStr = p(j), //08/28/2012 12:15 - 12:15
    timeStrSlice = dateStr.split(' ')[1].split(':'),
    h = parseFloat(timeStrSlice[0]),
    m = parseFloat(timeStrSlice[1]);

var nh = h,
    nm = m + 15;

if(nm > 60) {
   nh++;
   nm = 0;
}
if(nh > 24) {
   nh = 0;
}

var result = h + ":" + m + " " + nh + ":" + nm; // 12:15 12:30
1

According to the mobiscroll documentation setDate works with a Date object.

See this link on how to work with date objects in javascript. You don't need to do any string manipulations.

After you have the right date use the .scroller('setDate',newDate,true);

Levi Kovacs
  • 1,159
  • 8
  • 14
0

Date d = new Date(2012,08,28); d.setHours(12, 30, 0, 0);

Miki Shah
  • 815
  • 9
  • 20
0

See if this works for you:

var now = new Date();
//add 15 minutes to now
var out = new Date(now).setMinutes(now.getMinutes()+15)
Curious
  • 2,783
  • 3
  • 29
  • 45