java 时间现格式为00:00:00开始计时,如何表示
2个回答
展开全部
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
public class Test extends JFrame{
JLabel lbl=new JLabel();
Date now=new Date();
public Test() {
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
Timer timer=new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e) {
Date now2=new Date(now.getTime()+1000);
now=now2;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
lbl.setText(formatter.format(now));
}
});
timer.start();
this.setLayout(new FlowLayout());
this.add(lbl);
this.setSize(300,200);
this.setVisible(true);
}
public static void main(String[] args) {
Test t=new Test();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
public class Test extends JFrame{
JLabel lbl=new JLabel();
Date now=new Date();
public Test() {
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
Timer timer=new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e) {
Date now2=new Date(now.getTime()+1000);
now=now2;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
lbl.setText(formatter.format(now));
}
});
timer.start();
this.setLayout(new FlowLayout());
this.add(lbl);
this.setSize(300,200);
this.setVisible(true);
}
public static void main(String[] args) {
Test t=new Test();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class DateTest {
public static void main(String[] args) {
Calendar date = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd");
System.out.println(formatter.format(date.getTime()));
}
}
public static void main(String[] args) {
Calendar date = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd");
System.out.println(formatter.format(date.getTime()));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询