Transform tm timestamp to mm:ss.ccc string

@param int $time
@param bool $milliseconds

@return string
190220
public function timeToText($time, $milliseconds = false)
    {
        $sign = "";
        if ($time < 0) {
            $sign = "-";
        }
        $time = abs($time);
        $cent = str_pad(($time % 1000), 3, '0', STR_PAD_LEFT);
        $time = floor($time / 1000);
        $sec = str_pad($time % 60, 2, '0', STR_PAD_LEFT);
        $min = str_pad(floor($time / 60), 2, '0', STR_PAD_LEFT);
        $hour = str_pad(floor($time / 60 / 60), 1, '0');

        $textTime = $min.':'.$sec;
        if (floor($time / 60 / 60) > 0) {
            $textTime = $hour."'".$textTime;
        }

        if ($milliseconds) {
            $textTime = $textTime.'.'.$cent;
        }

        return $sign.$textTime;
    }
116499
public function convertStringToFloat($microtime)
    {
        /*
         * This is from the manual:
         * http://php.net/manual/en/function.microtime.php
         */
        // list($usec, $sec) = explode(" ", $microtime);
        
        // This seems to be more intuitive as an inverse function.
        list($usec, $sec) = sscanf($microtime, "%f %d");
        
        return ((float)$usec + (float)$sec);
    }
1369444
public static String datetime(long millis) {
		if (sFormat == null) {
			sFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("UTC"),
					US);
		}
		return sFormat.format(millis);
	}
787076
public static function formatStrTime($time, $withSeconds = true)
    {
        // Pad left with 0 in case we get numbers like 123, 12, 122015
        $time = str_pad($time.'', 6, '0', STR_PAD_LEFT);

        $_time = array();

        $_time[] = substr($time, 0, 2);
        $_time[] = substr($time, 2, 2);

        if ($withSeconds) {
            $_seconds = substr($time, 4, 2);
            $_time[] = $_seconds;
        }

        return implode(':', $_time);
    }
1273056
private function convertToSecondsIfNeeded($time)
    {
        if (!is_numeric($time)) {
            $now = microtime(true);

            $time = ceil(strtotime($time, $now) - $now);
        }

        return $time;
    }
645318
public static function createFromDateString($time)
    {
        $interval = parent::createFromDateString($time);
        if ($interval instanceof DateInterval && !($interval instanceof static)) {
            $interval = static::instance($interval);
        }

        return static::instance($interval);
    }
938712
public static function timestampToGmt($time = null)
    {
        $time = $time ?? time();
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($time)->modify('+2 hours');

        return $dateTime->format('d/m/Y H:i:s');
    }
724399
public static function fromTimestampWithMicroseconds(int $timestamp) : self
    {
        $seconds      = (int)($timestamp / 10 ** 6);
        $microseconds = $timestamp - ($seconds * 10 ** 6);

        // Ensure microseconds are right-padded with zeros because values like 012345 will be 12345 when expressed
        // as an integer, and the concatenation below will therefore shift digits left by one place.
        $microseconds = str_pad($microseconds, 6, '0', STR_PAD_LEFT);
        
        return static::fromFormat('U.u', $seconds . '.' . $microseconds);
    }
432265
public static function _convert_time($time)
    {
        $reference = new DateTimeImmutable;
        $endTime = $reference->add(new DateInterval($time));

        return $endTime->getTimestamp() - $reference->getTimestamp();
    }
1365433
function addMilliseconds($milliseconds) {
        if (!is_int($milliseconds)) return false;
        if ($milliseconds == 0) return true;
        $millisecond = $this->millisecond + $milliseconds;
        $milliseconds = $millisecond % 1000;
        if ($milliseconds < 0) {
            $milliseconds += 1000;
        }
        $seconds = (int)(($millisecond - $milliseconds) / 1000);
        $millisecond = (int)$milliseconds;
        if ($this->addSeconds($seconds)) {
            $this->millisecond = (int)$milliseconds;
            return true;
        }
        else {
            return false;
        }
    }
678225
public static function timeToText($time)
    {
        $timeHour   = ceil($time * 60);
        $modMinutes = $timeHour % 60;
        $hour       = floor($time);

        return $hour . ' h ' . $modMinutes . ' m';
    }
447204
public static function timestamp($timestamp = null)
    {
        if (!self::isDebug()) {
            return false;
        }

        $date = date(DATE_RFC822, $timestamp);
        return self::i()->dump($date, $timestamp . ' sec = ');
    }
931226
public static function createTimestamp($time = null, $format = 'Y-m-d H:i:s') {
        if ($time === null) {
            $time = time();
        }
        elseif (is_string($time)) {
            $time = strtotime($time);
        }

        return date($format, $time);
    }
792658
static function sGetMicrotime()
    {
        list ($usec, $sec) = explode(" ", microtime());
        return (( float )$usec + ( float )$sec);
    }
936583
public function setReceiveDelay($milliseconds = null)
    {
        if (is_integer($milliseconds)
            && $milliseconds >= self::DEF_RECEIVE_DELAY
        ) {
            $this->_receivedelay = $milliseconds;
        } else {
            $this->_receivedelay = self::DEF_RECEIVE_DELAY;
        }
        return $this->_receivedelay;
    }
601636
public static function toUnix($time) {
        if (!$time) {
            return time();

        } else if ($time instanceof DateTime) {
            return $time->format('U');
        }

        return is_string($time) ? strtotime($time) : (int) $time;
    }
104189
public static String toTimeString(long time, boolean millis) {
		GregorianCalendar cal = new GregorianCalendar(0, 0, 0);
		cal.setTimeInMillis(time);
		return toTimeString(cal, millis);
	}