java获取应用的运行时间,可以利用时间差来获得,使用System.currentTimeMillis()该方法获得此时的时间,代码如下:package com.qiu.lin.he;import java.text.ParseException;public class Ceshi {public static void main(String[] args) throws ParseException {double begin = System.currentTimeMillis(); ...
java 如何获取应用的运行时间
double begin = System.currentTimeMillis(); //程序开始时间,调用系统的当前时间
//你要运行的程序
double end = System.currentTimeMillis(); //程序结束时间,调用系统当前时间
time=end-begin;//程序的运行时间2012-06-20
最简单的例子,给你,希望有用。如有收获,请采纳!!!
package 数字电子表;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class Accutron extends JFrame implements Runnable {
private JLabel label;
public Accutron(){
super("北京时间");
setResizable(false);//禁止调整窗体的大小
setAlwaysOnTop(true);//窗体置顶
setTitle("北京时间");
setBounds(100,100,196,115);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel();
label.setFont(new Font("微软雅黑",Font.BOLD,24));
label.setForeground(Color.YELLOW);
label.setHorizontalAlignment(SwingConstants.CENTER);//设置标签内容居中
label.setHorizontalTextPosition(SwingConstants.CENTER);//设置文字内容居中
//ImageIcon icon = new ImageIcon("image/background.jpg");
//创建背景图片
//label.setIcon(icon);
getContentPane().add(label,BorderLayout.CENTER);
}
@Override
public void run() {
while(true){
Date date = new Date();
String timeStr = String.format("%tH:%tM:%tS%tp",date,date,date,date);
label.setText(timeStr);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
Accutron frame = new Accutron();
frame.setVisible(true);
new Thread(frame).start();
}catch(Exception e){
e.printStackTrace();
}
}
});
}
}2012-06-20
java获取应用的运行时间,可以利用时间差来获得,使用System.currentTimeMillis()该方法获得此时的时间,代码如下:
package com.qiu.lin.he;import java.text.ParseException;public class Ceshi {public static void main(String[] args) throws ParseException {double begin = System.currentTimeMillis(); // 程序开始时间,调用系统的当前时间for (int i = 0; i < 10000; i++) {// 这里执行具体的业务逻辑System.out.println(i);}// 你要运行的程序double end = System.currentTimeMillis(); // 程序结束时间,调用系统当前时间double time = end - begin;// 程序的运行时间System.out.println(time / 60 + "秒");}}运行结果如下:
2015-11-12
可以使用System.currentTimeMillis();这个命令,在程序一开始的时候获取一个long类型的时间,然后在程序运行结束的时候也是用System.currentTimeMillis();获取一个时间,然后求两者的差2012-06-20
创建一个日历类就可以获得了撒。2012-06-20