time_hms ( $seconds )

Convert a number of seconds into Hours:Minutes:Seconds.

Access

public

Parameters

Parameter

Type

Required

Description

$seconds

integer

Required

The number of seconds to convert.

Returns

Type

Description

string

The formatted time.

Examples

Converts a number of seconds into HH:MM:SS format.

// Instantiate
$s3 = new AmazonS3();

// Test data
var_dump($s3->util->time_hms(98765));
Result:
string(8) "27:26:05"

Source

Method defined in utilities/utilities.class.php | Toggle source view (18 lines) | View on GitHub

public function time_hms($seconds)
{
    $time = '';

    // First pass
    $hours = (int) ($seconds / 3600);
    $seconds = $seconds % 3600;
    $minutes = (int) ($seconds / 60);
    $seconds = $seconds % 60;

    // Cleanup
    $time .= ($hours) ? $hours . ':' : '';
    $time .= ($minutes < 10 && $hours > 0) ? '0' . $minutes : $minutes;
    $time .= ':';
    $time .= ($seconds < 10) ? '0' . $seconds : $seconds;

    return $time;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback