-1

I'm using extjs Date object in the format, Fri Dec 18 2015 00:00:00 GMT+0530 and hour and minute format(11:30AM), now how can I add 11.30am to date object?

Mehul Tandale
  • 331
  • 1
  • 5
  • 17
vinod
  • 3
  • 2
  • Welcome to stackoverflow. Try to be more "complete" in your question, adding some code and with some more comment on your situation, thanks – RiccardoC Nov 23 '15 at 10:16
  • i have date object( Fri Dec 18 2015 00:00:00 GMT+0530) and i have string object (11:30Am) and i my output should be Fri Dec 18 2015 00:11:30 GMT+0530. – vinod Nov 23 '15 at 10:19

1 Answers1

0

Assuming your string is always in the format "HH:mm(a|p)m", you could do something like this:

var d = new Date(2015, 11, 18),
    s = '11:30am',
    isPM = s.indexOf('p') > -1,
    hours = parseInt(s.substr(0, 2), 10),
    minutes;

if (hours !== 12) {
    hours += isPM ? 12 : 0;
} else if (!isPM) {
    hours = 0;
}
minutes = parseInt(s.substr(3, 2), 10) + (hours * 60);


d = Ext.Date.add(d, Ext.Date.MINUTE, minutes);
console.log(d);
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66