我想要登录&退出系统时间
Process uptimeProc = Runtime.getRuntime().exec("net stats srv");
BufferedReader in = new BufferedReader(new inputStreamReader(uptimeProc.getInputStream()));
String line;
while ((line = in.readLine()) != null)
{
if(line.contains("Statistics since"))
{
SimpleDateFormat format = new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm:ss a");
//System.out.println("in ijj "+in.readLine());
Date boottime = format.parse(line);
System.out.println("Uptime="+uptime+""+boottime);
uptime = System.currentTimeMillis() - boottime.getTime();
break;
}
}
执行此代码后,它会抛出异常,如
Exception in thread "main" java.text.ParseException: Unparseable date: "Statistics since 6/16/2014 10:08 AM"
at java.text.DateFormat.parse(DateFormat.java:337)
at programs.GetLoginTimeYaar.getSystemUptime(GetLoginTimeYaar.java:44)
at programs.GetLoginTimeYaar.main(GetLoginTimeYaar.java:14)
PLZ回复
答案 0 :(得分:0)
您必须删除模式中的秒数:
new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm a");
答案 1 :(得分:0)
尝试
new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm a");
因为您的日期不包含秒数。