1、通过date类来获取当前时间
date day=new date(); simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss"); system.out.println(df.format(day));
2、通过system类中的currenttimemillis方法来获取当前时间
simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss"); system.out.println(df.format(system.currenttimemillis()));
3、通过calendar类来获取当前时间
calendar c = calendar.getinstance();//可以对每个时间域单独修改 int year = c.get(calendar.year); int month = c.get(calendar.month); int date = c.get(calendar.date); int hour = c.get(calendar.hour_of_day); int minute = c.get(calendar.minute); int second = c.get(calendar.second); system.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
4、通过date类来获取当前时间
date date = new date(); string year = string.format("%ty", date); string month = string.format("%tb", date); string day = string.format("%te", date); system.out.println("今天是:"+year+"-"+month+"-"+day);
推荐:《java视频教程》
以上就是java如何获取系统时间的详细内容。
