Java 动态显示当前系统的日期、时间;如图所示:
创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都网站制作、网站设计、外贸网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元湾里做网站,已为上家服务,为湾里各地企业和个人服务,联系电话:028-86922220
package com.xin.test;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.JFrame;
public class NowTime extends JFrame {
private static final long serialVersionUID = 4306803332677233920L;
// 添加 显示时间的JLabel
public NowTime() {
JLabel time = new JLabel();
time.setForeground(Color.BLUE);
time.setBounds(30, 0, 900, 130);
time.setFont(new Font("微软雅黑", Font.BOLD, 80));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setTitle("now time");
this.setBounds(500, 200, 930, 200);
this.setVisible(true);
this.add(time);
this.setTimer(time);
}
// 设置Timer 1000ms实现一次动作 实际是一个线程
private void setTimer(JLabel time) {
final JLabel varTime = time;
Timer timeAction = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
long timemillis = System.currentTimeMillis();
// 转换日期显示格式
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
varTime.setText(df.format(new Date(timemillis)));
}
});
timeAction.start();
}
// 运行方法
public static void main(String[] args) {
new NowTime();
}
}另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。