java获取系统当前时间的方法
这篇文章主要介绍java获取系统当前时间的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
java获取系统当前时间的方法:获得当前时间和当前时间前30秒时间,代码为【SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");】。
java获取系统当前时间的方法:
import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; /** * @author ceshi * @Title: ceshi * @ProjectName ceshi * @Description: TODO * @date 2018/7/59:48 */ public class JunitCalendar { @Test public void test(){ //获得当前时间和当前时间前30秒时间 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = new GregorianCalendar(); Date date = new Date(); System.out.println("系统当前时间"+df.format(date)); //设置参数时间 c.setTime(date); //SECOND 秒 整数增加,负数减少 c.add(Calendar.SECOND,-10); System.out.println("系统前10秒时间:"+df.format(c.getTime())); //DAY_OF_MONTH 天 整数增加,负数减少 c.add(Calendar.DAY_OF_MONTH,1); System.out.println("系统前1天时间:"+df.format(c.getTime())); } }
以上是“java获取系统当前时间的方法”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!