Date format 24h without a space preceding single digits

Viewed 740

I have the following

$nextDisponibility->formatLocalized('%A %e %B à %kh%M')

which gives me

lundi 13 novembre à 8h00

How could I remove the space before the single hour digit ?

From php doc:

%k Hour in 24-hour format, with a space preceding single digits 0 through 23

Is preg_replace('!\s+!', ' ', $nextDisponibility->formatLocalized('%A %e %B à %kh%M')); the best way to do this ?

1 Answers

If you don't want to do string manipulations you can probably do something more "hacky":

$string = $nextDisponibility->formatLocalized('%A ')
.trim($nextDisponibility->formatLocalized("%e"))
.$nextDisponibility->formatLocalized(" %B ")
.ltrim($nextDisponibility->formatLocalized("%kh%M"));

However $string = str_replace(' ',' ',$nextDisponibility->formatLocalized('%A %e %B à %kh%M')) is probably better if you don't care about other double spaces.

Related