java如何获取系统当前时间爪哇如何获取系统当前时间,爪哇岛获取系统当前时间的方法:获得当前时间和当前时间前30秒时间,代码为【简单日期格式df=新的简单日期格式(‘ yyyy-MM-DD hh :MM 3360s ‘);】。
本教程操作环境:windows7系统java10版,该方法适用于所有品牌电脑。
java获取系统当前时间的方法:
导入组织。JUnit。测试;
导入Java。文字。SimpleDateformat
导入Java。util。日历;
导入Java。util。日期;
导入Java。util。Gregoriancalendar
/**
* @作者史策
* @Title:史策
* @项目名称史策
* @Description: TODO
* @date 2018/7/59:48
*/
公共类JunitCalendar {
@测试
public void test(){
//获得当前时间和当前时间前30秒时间
simpledate格式df=new simpledate格式(‘ yyyy-MM-DD hh :MM 3360s ‘);
日历c=新公历();
Date Date=new Date();
System.out.println(‘系统当前时间df。格式(日期));
//设置参数时间
c.setTime(日期);
//第二秒整数增加,负数减少
添加(日历. SECOND,-10);
System.out.println(‘系统前10秒时间:’ df。format(c . GetTime());
//月_日天整数增加,负数减少
添加(日历。年月日,1);
System.out.println(‘系统前一天时间:’ df。format(c . GetTime());
}
}相关免费学习推荐:java基础教程