The TimeFormatter promotes time values between multiple units.
- Non-numeric input is returned unchanged.
- Promotion is based on magnitude.
- Output uses symbols only (no spaces), e.g.
1h,500ms.
use Respect\StringFormatter\TimeFormatter;
$formatter = new TimeFormatter('s');
echo $formatter->format('60');
// Outputs: 1min
echo $formatter->format('0.001');
// Outputs: 1ms__construct(string $unit)
The $unit is the input unit (the unit you are providing values in).
Accepted symbols:
ns,us,ms,s,min,h,d,w,mo,y,dec,c,mil
yuses a fixed year of 365 days.mouses 1/12 of a fixed year (approx. 30.41 days).wuses 7 days.dec,c, andmilare based on that fixed year.