首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎么获取开机时刻到现在时刻的秒数

2012-08-24 
如何获取开机时刻到现在时刻的秒数?如何获取开机时刻到现在时刻的秒数?[解决办法]Java codeimport java.io

如何获取开机时刻到现在时刻的秒数?
如何获取开机时刻到现在时刻的秒数?

[解决办法]

Java code
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.text.SimpleDateFormat;import java.util.Calendar;public class Test {    public static void main(String[] args) throws Exception {        String startstr = Test.readSystemStartTime();        String startdate = startstr.substring(7,startstr.length());        Calendar c = Calendar.getInstance();        c.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startdate));        System.out.println("开前到现在的毫秒数:" + (System.currentTimeMillis() - c.getTimeInMillis()));    }    public static String readSystemStartTime() throws IOException, InterruptedException {        Process process = Runtime.getRuntime().exec("cmd /c net statistics workstation");        String startUpTime = "";        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));        int i = 0;        while ((startUpTime = bufferedReader.readLine()) != null) {            if (i == 3) {                break;            }            i++;        }        process.waitFor();        return startUpTime;    }}
[解决办法]
String startdate = startstr.substring(7,startstr.length());

--------------

不同的系统可能显示的不一样

热点排行
Bad Request.