How do I say 5 seconds from now in Java?

后端 未结 11 1840
青春惊慌失措
青春惊慌失措 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 15:57

    Date is almost entirely deprecated and is still there for backward compatibility reasons. If you need to set particular dates or do date arithmetic, use a Calendar:

    Calendar calendar = Calendar.getInstance(); // gets a calendar using the default time zone and locale.
    calendar.add(Calendar.SECOND, 5);
    System.out.println(calendar.getTime());
    

提交回复
热议问题