如何用JAVA把两个时间相减
来源:百度知道 编辑:UC知道 时间:2024/05/29 05:10:00
(为了显示给用户看,不需要多线程,只显示一遍)
2.获得上机时间和下机时间后如何转化为毫秒格式
(用于时间相减得出使用时间的毫秒数)
急求 复制的别来 鄙视
最好用// 注明哪里是解答我第一个问题和第二个问题的
谢谢了 满意绝对加分! 分是小事
Date d = new Date();//获得当前时间
DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式化时间
System.out.println(f.format(d));//格式化显示
Long ms = d.getTime();//获得毫秒值
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.SimpleDateFormat;
class dd extends Frame implements ActionListener
{
long x=System.currentTimeMillis();
TextField tt,t1;
Button bb,bv;
SimpleDateFormat sim;
Date time;
dd()
{
tt=new TextField(18);t1=new TextField(18);
bb=new Button("显示当前时间");
bv=new Button("显示上机时间");
setLayout(new FlowLayout());
time=new Date(x);
String s="yyyy-MM-dd HH:mm:ss";
sim=new SimpleDateFormat(s);
System.out.print(""+sim.format(time));
add(bb);
bb.addActionListener(this);
bv.addActionListener(this);
add(tt);
add(bv);