Carbon: formatLocalized %p (for AM/PM) not displaying anything

Created on 2 Dec 2016  路  7Comments  路  Source: briannesbitt/Carbon

using ->formatLocalized('%e %B %Y, %I:%M:%S %p')

the %p part is empty.

Most helpful comment

echo Carbon::now()->formatLocalized('%e %B %Y, %I:%M:%S %p'); gives me 2 December 2016, 10:09:06 AM

All 7 comments

echo Carbon::now()->formatLocalized('%e %B %Y, %I:%M:%S %p'); gives me 2 December 2016, 10:09:06 AM

Using php 7 ?

It was on 5.6 ... but here it is again on 7.1

z:\dev\CarbonPlay>php -v
PHP 7.1.0 (cli) (built: Dec  2 2016 05:24:39) ( NTS MSVC14 (Visual C++ 2015) x64 )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

z:\dev\CarbonPlay>php try.php
2 December 2016, 11:42:09 AM

it appears to have to do with:

setlocale(LC_TIME, "fr_CA.utf8");

in my code...

For the french locale (and others) %p in strftime is empty or a single space. The absence of AM/PM for some locales is correct as 24 hour time is usually the norm and sometimes there is no one-to-one equivalent for "am" or "pm".

my bad!

we do use am/pm though in french.

Terrific library mate, congratz on it's success :)

Was this page helpful?
0 / 5 - 0 ratings