aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/format_datetime.php
diff options
context:
space:
mode:
Diffstat (limited to 'misc/format_datetime.php')
-rw-r--r--misc/format_datetime.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/misc/format_datetime.php b/misc/format_datetime.php
new file mode 100644
index 0000000..1a4db52
--- /dev/null
+++ b/misc/format_datetime.php
@@ -0,0 +1,14 @@
+<?php
+
+function format_datetime(
+ DateTimeInterface $dt,
+ DateTimeZone|IntlTimeZone|string|null $tz = null
+): string {
+ static $formatter = new IntlDateFormatter(
+ get_ui_language(),
+ IntlDateFormatter::RELATIVE_MEDIUM,
+ IntlDateFormatter::SHORT
+ );
+ $formatter->setTimeZone($tz ?? $dt->getTimezone());
+ return $formatter->format($dt);
+} \ No newline at end of file