0

I have a problem using the IntlDateFormatter class.

The following code gives different results if it is executed by apache or cli

<?php

$obj_formato = new IntlDateFormatter(setlocale(LC_TIME, 0), null, null);
$obj_formato->setPattern("MMM");
for($i=1; $i<13; $i++) {
    print $obj_formato->format(strtotime("2022-$i-01")) . PHP_EOL;
}

Apache: ene. feb. mar. abr. may. jun. jul. ago. sept. oct. nov. dic.

CLI: ene. feb. mar. abr. may. jun. jul. ago. sep. oct. nov. dic.

The result by CLI returns "Sept.", by Apache it returns "Sep." It is also the only month where the returned result contains 4 letters

I am using PHP 7.4.33

Any help?

I'm trying to get the short names of the months without using strftime()

  • 1
    There are locales that use "Sep" and others use "Sept" - chances are, your default locale in the web server is different from the default cli locale. – Jim Apr 18 '23 at 00:06
  • I was finally able to work around using Locale::getDefault() as the first parameter of IntlDateFormatter() Thank you! – framirezfa Apr 18 '23 at 14:22

0 Answers0