How do I say 5 seconds from now in Java?

后端 未结 11 1839
青春惊慌失措
青春惊慌失措 2020-12-02 15:29

I am looking at the Date documentation and trying to figure out how I can express NOW + 5 seconds. Here\'s some pseudocode:

import java.util.Date
public clas         


        
11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 16:03

    As others have pointed out, in Joda it's much easier:

    DateTime dt = new DateTime();
    DateTime added = dt.plusSeconds(5);
    

    I would strongly recommend you migrate to Joda. Almost any Java date-related question on SO resolves to a Joda recommendation :-) The Joda API is supposed to be the basis of the new standard Java date API (JSR310), so you'll be migrating towards a new standard.

提交回复
热议问题