How to convert the seconds in this format “HH:mm:ss”

前端 未结 6 603
栀梦
栀梦 2021-02-06 23:31

I want to convert the second/milliseconds in this format \"HH:mm:ss\" (for esamples, from 5 seconds to 00:00:05). I tried to get that format in this way:

int mil         


        
6条回答
  •  死守一世寂寞
    2021-02-07 00:18

    public class HHMMSS {
    
            final int UUR = 3600;
            final int MINUUT = 60;
    
        public void converteerTijd() {
    
            int uren, minuten, seconden, ingave;
            System.out.print("Geef een aantal seconden: ");
            ingave = Input.readInt();
            uren = ingave / UUR;
            minuten = (ingave - uren * UUR) / MINUUT;
            seconden = ingave - uren * UUR - minuten * MINUUT;
            String nU1 = (uren < 10) ? "0" : "";
            String nM1 = (minuten < 10) ? "0" : "";
            String nS1 = (seconden < 10) ? "0" : "";
            System.out.println(nU1 + uren + "-" + nM1 + minuten + "-" + nS1 + seconden);
    

提交回复
热议问题