Hey Ruud.

Am 13.03.18 um 20:18 schrieb ruud.bak...@caiway.nl:
> As there is no function for getting a real local date for day names and month 
> names, I wrote a function for that. Maybe an option for a new PHP version?
> 
> <?php
> 
> function localdate(string $format, int $timestamp, string $locale) {
>     
>     $oldlocale = setlocale(LC_TIME, 0);
>     setlocale(LC_TIME, $locale);
> 
>     $date = '';
>     for ($i = 0; $i < strlen($format); $i++) {
> 
>         $char = substr($format, $i, 1);
>         switch ($char) {
>             case 'D':
>                 $date .= strftime('%a', $timestamp);
>                 break;
>             case 'l':
>                 $date .= strftime('%A', $timestamp);
>                 break;
>             case 'M':
>                 $date .= strftime('%b', $timestamp);
>                 break;
>             case 'F':
>                 $date .= strftime('%B', $timestamp);
>                 break;
>             default:
>                 $date .= date($char, $timestamp);
>                 break;
>         }
>     }
> 
>     setlocale(LC_TIME, $oldlocale);
> 
>     return $date;
> }

May I ask what you actually mean by "real local date for day names and
month names"?

Or is this something like this:

<?php
$fmt = IntlDateFormatter::formatObject(new DateTime(), 'MMMM', 'nl_NL');
echo 'Month is ' . $fmt;
// will output "Month is maart" for the next few days ;)
?>

Cheers

Andreas

-- 
                                                              ,,,
                                                             (o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl                                                       |
| mailto:andr...@heigl.org                  N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org                       http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca                                               |
+---------------------------------------------------------------------+

Attachment: 0x5BFCE472.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to