Browse project documentation

Formatting

Daynumv1.0.0-beta.4View sourceEnglish / Persian

Format calendar dates with supported PHP-style tokens.

Format a view

Call format($pattern) on a calendar view. The formatter supports the tokens below, not every token of every PHP version. Unknown characters pass through; escape a token letter with a backslash for literal text. A cast to string uses Y-m-d for Gregorian and Y/m/d for the other views.

<?php
require 'vendor/autoload.php';

use Eram\Daynum\CivilDateTime;

$v = CivilDateTime::fromGregorian(2026, 4, 8, 14, 30, 0, 'Asia/Tehran')
    ->jalali()->withLocale('fa')->withDigits('persian');
echo $v->format('Y/m/d H:i P'), "\n";
echo $v->format('c'), "\n";
echo $v->format('\\Y Y'), "\n";
۱۴۰۵/۰۱/۱۹ ۱۴:۳۰ +03:30
2026-04-08T14:30:00+03:30
Y ۱۴۰۵

Token reference

TokensMeaning
Y yCalendar year, at least four digits / last two digits
m n F MMonth padded / unpadded / full name / short name
d j SDay padded / unpadded / locale ordinal suffix
l D N wFull / short weekday name; Monday=1 / Sunday=0 numbering
zZero-based day of year (dayOfYear() is one-based)
W oWeek number / week-based year using the Thursday rule in this calendar
t LDays in month / leap-year flag
H G h g24-hour padded / unpadded; 12-hour padded / unpadded
i s a AMinute, second, locale AM/PM markers
u vAlways 000000 / 000 (no subsecond storage)
e TStored timezone label / PHP timezone abbreviation
O P p Z I UOffset, offset with colon, offset or Z, offset seconds, DST flag, Unix seconds
c rPHP Gregorian ISO 8601 / RFC 2822 output

e T O P p Z I U c r require a non-null timezone label. Except for e, which prints the label directly, these use native PHP timezone resolution and may reject an invalid label. Their output bypasses digit conversion. c and r always use Gregorian dates even on a Jalali or Hijri view; other calendar tokens use the selected calendar. At DST gaps, native output may normalize the wall-clock reading; see timezones.

W and o may throw at range boundaries. They do not adopt locale week starts. S is locale-dependent (empty in Persian and Arabic). Arabic locale has no Jalali month names: F/M throw there. Read localization and parsing before assuming formatted strings can be parsed back.

Search documentation

Search across all projects. Close this window to return to your guide.

Tab to navigate · Enter to openEsc to close