Date output for tenth of seconds?

682 Views Asked by At

I'm storing laptimes in a database in the following format: 103.900.

I'm outputting time from the database by using the following date format:

date('i:s.U', $video->best_lap)

What i get back is: 01:43.103. The actual output time should display 01:43.900. Is there someway I can make PHP play nicely?

1

There are 1 best solutions below

0
Mark Baker On BEST ANSWER

PHP's date functions (using unix timestamps, which are integer values) don't support fractional seconds (as described in the PHP Docs)

Note: Since this function only accepts integer timestamps the u format character is only useful when using the date_format() function with user based timestamps created with date_create().

And note also that the fractional part format mask is u, not U (lower-case, not upper-case)

However, DateTime objects do support fractional seconds, so you can use:

$dto = DateTime::createFromFormat('U.u', '103.900');
echo $dto->format('i:s.u');