-2

i am getting in Json format the follow

09\/14\/2013 14:00

i would like to add minutes to the date and display the value as string should i convert it to datetime, add and convert back? if yes then how?

Chehmer
  • 443
  • 1
  • 5
  • 8
  • you mean add minutes as in manipulation of time (say current time + 60 minutes)? – Harry Sep 06 '13 at 13:23
  • May help you http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object – Felipe Oriani Sep 06 '13 at 13:24
  • Is this helpful http://stackoverflow.com/questions/1933320/convert-a-date-to-string-in-javascript – mic4ael Sep 06 '13 at 13:24
  • 1
    best way is to use `new Date()` it will create the current time. Then just wait however many minutes you need, then call it again. That should work – musefan Sep 06 '13 at 13:25

2 Answers2

2

Try this code

var dat = new Date('09/14/2013 14:00'); // Change the string to Date
console.log(dat);
console.log(dat.getMinutes()); // Get the minutes of your dateTime
dat.setMinutes('23'); // Set the minutes you wish
console.log(dat);
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

Once you have converted this to a Date() object in Javascript, you can use the getMinutes() function to obtain the minutes in the date, perform your logic to add minutes, and then set the minutes using the setMinutes() function.

Praveen
  • 55,303
  • 33
  • 133
  • 164
Robert Gannon
  • 253
  • 4
  • 13