您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java如何获取系统时间

2024/3/12 0:41:52发布32次查看
本篇文章给大家介绍一下java获取系统时间的四种方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
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如何获取系统时间的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product