Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

javascript - 给Javascript日期对象timeObject增加10秒(Add 10 seconds to a Javascript date object timeObject)

How can I add 10 seconds to a javascript date object timeObject.(如何向JavaScript日期对象timeObject添加10秒。)

Something like this I think..(我想是这样的) var timeObject = new Date() var seconds = timeObject.getSeconds() + 10; timeObject = timeObject + seconds;   ask by george translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's a setSeconds method as well:(还有一个setSeconds方法:)

var t = new Date(); t.setSeconds(t.getSeconds() + 10); For a list of the other Date functions, you should check out MDN(有关其他 Date功能的列表, 您应该签出MDN) setSeconds will correctly handle wrap-around cases:(setSeconds将正确处理环绕情况:) var d; d = new Date('2014-01-01 10:11:55'); alert(d.getMinutes() + ':' + d.getSeconds()); //11:55 d.setSeconds(d.getSeconds() + 10); alert(d.getMinutes() + ':0' + d.getSeconds()); //12:05

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...