在Java中如何说5秒? [英] How do I say 5 seconds from now in Java?
本文介绍了在Java中如何说5秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查看日期文档并试图找出我如何表达现在+ 5秒。这里有一些伪代码:
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 class Main {
public static void main(String args[]) {
Date now = new Date();
now.setSeconds(now.getSeconds() + 5);
}
}
推荐答案
一个href =http://java.sun.com/javase/6/docs/api/java/util/Date.html =noreferrer> Date 几乎完全被弃用,还在向后兼容性原因如果您需要设置特定日期或日期算术,请使用日历:
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());
这篇关于在Java中如何说5秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文