Dynamic Clock in java

后端 未结 7 1056
我在风中等你
我在风中等你 2020-12-16 02:22

I want to implement a clock within my program to diusplay the date and time while the program is running. I have looked into the getCurrentTime() method and

相关标签:
7条回答
  • 2020-12-16 03:25
        Timer timer = new Timer(1000, (ActionEvent e) -> {
            DateTimeFormatter myTime = DateTimeFormatter.ofPattern("HH:mm:ss");
            LocalDateTime now = LocalDateTime.now(); 
            jLabel1.setText(String.valueOf(myTime.format(now)));
        });
        timer.setRepeats(true);
        timer.start();
    
    0 讨论(0)
提交回复
热议问题