I have a date string that looks like the following javascript format. I want to convert this to a date object and add one minute.
timeObject = "Mon Nov 07 2011 06:41:48 GMT-0500 (Eastern Standard Time)";
timeObject.setSeconds(timeObject.getSeconds() + 60);
====== SOLUTION ==========
never mind. I got it...
var time = $('#myDiv').val(); // = "Mon Nov 07 2011 06:41:48 GMT-0500 (Eastern Standard Time)";
var timeObject = new Date(time);
alert(timeObject);
timeObject.setSeconds(timeObject.getSeconds() + 60);
alert(timeObject);
I have a date string that looks like the following javascript format. I want to convert this to a date object and add one minute.
timeObject = "Mon Nov 07 2011 06:41:48 GMT-0500 (Eastern Standard Time)";
timeObject.setSeconds(timeObject.getSeconds() + 60);
====== SOLUTION ==========
never mind. I got it...
var time = $('#myDiv').val(); // = "Mon Nov 07 2011 06:41:48 GMT-0500 (Eastern Standard Time)";
var timeObject = new Date(time);
alert(timeObject);
timeObject.setSeconds(timeObject.getSeconds() + 60);
alert(timeObject);
Share
Improve this question
edited Nov 7, 2011 at 11:59
Mustapha George
asked Nov 7, 2011 at 11:52
Mustapha GeorgeMustapha George
2,52710 gold badges49 silver badges87 bronze badges
2
- You should post your solution as an answer and accept it. – zatatatata Commented Nov 7, 2011 at 12:10
- 1 system would not let me. not enough points. – Mustapha George Commented Nov 7, 2011 at 12:13
2 Answers
Reset to default 36Proper way is:
timeObject.setTime(timeObject.getTime() + 1000 * 60);
Another approach could be using .setMinutes()
:
timeObject.setMinutes(timeObject.getMinutes() + 1)
Even if adding n
minute(s) would cause a change of hour/day/month/year, the Date
object already calculates this for you so you don't have to worry. Check here for an example.