How to set time to 24 hour format in Calendar

后端 未结 9 1483
迷失自我
迷失自我 2020-12-25 12:10

I need to set the time on the current date. The time string is always in 24 hour format but the result I get is wrong:

  SimpleDateFormat df = new SimpleDate         


        
9条回答
  •  渐次进展
    2020-12-25 12:43

    private void setClock() {

        Timeline clock = new Timeline(new KeyFrame(Duration.ZERO, e -> {
            Calendar cal = Calendar.getInstance();
            int second = cal.get(Calendar.SECOND);
            int minute = cal.get(Calendar.MINUTE);
            int  hour = cal.get(Calendar.HOUR_OF_DAY);
            eski_minut = minute;
            if(second < 10){
    
                time_label.setText(hour + ":" + (minute) + ":0" + second);
    
            }else if (minute < 10){
                time_label.setText(hour + ":0" + (minute) + ":0" + second);
    
            }
            else {
            time_label.setText(hour + ":" + (minute) + ":" + second);}
        }),
                new KeyFrame(Duration.seconds(1))
        );
        clock.setCycleCount(Animation.INDEFINITE);
        clock.play();
    }
    

提交回复
热议问题