German dates with IntlDateFormatter

So, I’ve this example vanilla php code:

<?php

$format = new IntlDateFormatter("de_DE", IntlDateFormatter::FULL, IntlDateFormatter::SHORT, 'Europe/Berlin');


echo datefmt_format($format, time());

and the output looks great:

Dienstag, 12. September 2023 um 18:48%

So I could just stick to this, but I want to use kirby as much as possible so I’ve set the date.handler to intl. But what’s next? I don’t have get the date from a page field, I read it from a database so I thought I could just use kirby’s Date:: methods, but I don’t know how to glue it together with IntlDateFormatter. Also I would have thought that when I use the intl handler and also set the locale, that I don’t have to come up with my own format definition as above. Sadly the docs only show how to use it with page fields: Working with dates | Kirby CMS

Outside of the field context, you can use

  echo Str::date(time(), 'EEEE, MMMM d, YYYY', 'intl');
  echo Str::date(time(), new IntlDateFormatter("de_DE", IntlDateFormatter::FULL, IntlDateFormatter::SHORT, 'Europe/Berlin'), 'intl');

1 Like

Thank you @texnixe, where can I buy you a coffee? :raised_hands: