Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Java dynamically displays the current date and time

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, Xiaobian will bring you about Java dynamics how to display the current date and time. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.

Java dynamically displays the date and time of the current system; as shown in the figure:

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 = 43068033267723920L; //Add JLabel public NowTime() { JLabel time = new JLabel(); time.setForeground (Color.BLUE); time.setBounds (30, 0, 900, 130); time.setFont (new Font("Microsoft Yahei", 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);} //Set Timer 1000ms to implement an action is actually a thread 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(); //convert date display format SimpleDateFormat df = new SimpleDateFormat ("y-MM-dd HH:mm:ss"); varTime.setText(df.format(new Date(timemillis))); } }); timeAction.start(); }/Method of operation public static void main(String[] args) { new NowTime(); } }

The above is a small series for everyone to share Java dynamics how to display the current date and time, if there is a similar doubt, may wish to refer to the above analysis to understand. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report