Runtime.getRuntime().exec("cmd /c date 2013-05-06");//Windows 系统
Runtime.getRuntime().exec("cmd /c time 22:35:00");//Windows 系统
Runtime.getRuntime().exec(" sudo date -s 2013-05-06")//linux 系统为tomcat用户分配了权限
Runtime.getRuntime().exec(" sudo date -s 22:25:00")//linux 系统为tomcat用户分配了权限
执行日期与时间设置的跨平台Java代码示例
本文提供了使用Java Runtime环境在不同操作系统上执行命令来修改日期和时间的代码示例,包括Windows和Linux系统。通过Runtime.getRuntime().exec()方法,实现了在Tomcat用户权限下为Linux系统设置日期和时间的功能。
1375

被折叠的 条评论
为什么被折叠?



