Different date (language/locale) handling in one Kirby environment

Hi,

In my config I prefere the international date handling with:

'date'  => [
      'handler' => 'intl'
    ],

'locale' => [
            'LC_ALL' => 'de_DE.utf8'
        ],

that in the html environment a German output is supported with:

page()->children()->listed()>date()->toDate('EEEE, dd MMM YYYY')

The output with German date names like “Mittwoch” is supported, so far so good.

But I need for a technical feed file in the background a time-stamp in english, in the date format (RFC 2822) with: Sat, 01 Apr 2023 19:00:00 GMT.

A code with:

$page->children()->listed()->date()->toDate('EEE, dd MMM yyyy HH:mm:ss ZZZZ')

supports the RFC 2822 output, but with German names for the week and month.

I’m looking for a possibility to change the locale only for the moment, where the function is called without an influence on the whole site.

Something like:

$page->children()->listed()->date()->language('en')->toDate('EEE, dd MMM yyyy HH:mm:ss ZZZZ')

but I have no success, especially to find something in the docs.

What can I do?

You can pass an DateFormatter object to the toDate() mehod, example:

<?= $page->date()->toDate(new IntlDateFormatter("fr_FR", IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'Europe/Berlin')); ?>

For details, see the PHP docs: PHP: IntlDateFormatter - Manual

Thank you very much.
Here is my complete example to produce a RFC 2822 time stamp output:

<?= $page->date()->toDate(new IntlDateFormatter("en_EN", IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'Europe/Berlin', null, 'EEE, dd MMM yyyy HH:mm:ss ZZZZ') ; ?>