最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript add one minute to time object - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 36

Proper 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.

发布评论

评论列表(0)

  1. 暂无评论