[Java] - Millisecond to time

Java 2018. 7. 19. 09:45
반응형

private String getTimeStamp( long milliSeconds ) {

    long time       = milliSeconds / 1000;

    String seconds = Integer.toString( ( int )( time % 60 ) );

    String minutes = Integer.toString( ( int )( ( time % 3600 ) / 60 ) );

    String hours   = Integer.toString( ( int )( time / 3600 ) );

    for( int i = 0; i < 2; i++ ) {

      if( seconds.length() < 2 ) {

        seconds = "0" + seconds;

      }

      if( minutes.length() < 2 ) {

        minutes = "0" + minutes;

      }

      if( hours.length() < 2 ) {

        hours = "0" + hours;

      }

    }


    String ddate = hours + ":" + minutes + ":" + seconds;

    return ddate;

  }

반응형
: