@@ -82,6 +82,103 @@ echo $formatphp->formatMessage([
8282]);
8383```
8484
85+ ### Formatting Dates and Times
86+
87+ You may use the methods ` formatDate() ` and ` formatTime() ` to format dates and
88+ times.
89+
90+ ``` php
91+ use FormatPHP\Config;
92+ use FormatPHP\FormatPHP;
93+ use FormatPHP\Intl;
94+
95+ $config = new Config(new Intl\Locale('es'));
96+ $formatphp = new FormatPHP($config);
97+
98+ $date = new DateTimeImmutable();
99+
100+ echo $formatphp->formatDate($date); // e.g. "21/1/22"
101+ echo $formatphp->formatTime($date); // e.g. "16:58"
102+ ```
103+
104+ #### Using Intl\DateTimeFormatOptions with formatDate() and formatTime()
105+
106+ Fine-tune date and time formatting with ` Intl\DateTimeFormatOptions ` .
107+
108+ ``` php
109+ echo $formatphp->formatDate($date, new Intl\DateTimeFormatOptions([
110+ 'dateStyle' => 'medium',
111+ ])); // e.g. "21 ene 2022"
112+ echo $formatphp->formatTime($date, new Intl\DateTimeFormatOptions([
113+ 'timeStyle' => 'long',
114+ ])); // e.g. "16:58:31 UTC"
115+ ```
116+
117+ ` DateTimeFormatOptions ` accepts the following general options for formatting
118+ dates and times:
119+
120+ * ` dateStyle ` : General formatting of the date, according to the locale. Possible
121+ values include: ` full ` , ` long ` , ` medium ` , and ` short ` .
122+ * ` timeStyle ` : General formatting of the time, according to the locale. Possible
123+ values include: ` full ` , ` long ` , ` medium ` , and ` short ` .
124+
125+ > ℹ️ ** Note:** ` dateStyle ` and ` timeStyle ` may be used together, but they cannot
126+ > be used with more granular formatting options (i.e., ` era ` , ` year ` , ` month ` ,
127+ > ` day ` , ` weekday ` , ` day ` , ` hour ` , ` minute ` , or ` second ` ).
128+
129+ Instead of ` dateStyle ` and ` timeStyle ` , you may use the following options for
130+ more granular formatting of dates and times:
131+
132+ * ` era ` : The locale representation of the era (e.g. "AD", "BC"). Possible values
133+ are: ` long ` , ` short ` , and ` narrow ` .
134+ * ` year ` : The locale representation of the year. Possible values are: ` numeric `
135+ or ` 2-digit ` .
136+ * ` month ` : The locale representation of the month. Possible values are: ` numeric ` ,
137+ ` 2-digit ` , ` long ` , ` short ` , or ` narrow ` .
138+ * ` weekday ` : The locale representation of the weekday name. Possible values are:
139+ ` long ` , ` short ` , and ` narrow ` .
140+ * ` day ` : The locale representation of the day. Possible values are: ` numeric ` or
141+ ` 2-digit ` .
142+ * ` hour ` : The locale representation of the hour. Possible values are: ` numeric `
143+ or ` 2-digit ` .
144+ * ` minute ` : The locale representation of the minute. Possible values are:
145+ ` numeric ` or ` 2-digit ` .
146+ * ` second ` : The locale representation of the seconds. Possible values are:
147+ ` numeric ` or ` 2-digit ` .
148+
149+ Additional options include:
150+
151+ * ` calendar ` : The calendar system to use. Possible values include: ` buddhist ` ,
152+ ` chinese ` , ` coptic ` , ` dangi ` , ` ethioaa ` , ` ethiopia ` , ` ethiopic ` , ` gregory ` ,
153+ ` hebrew ` , ` indian ` , ` islamic ` , ` islamic-civil ` , ` islamic-rgsa ` , ` islamic-tbla ` ,
154+ ` islamic-umalqura ` , ` iso8601 ` , ` japanese ` , ` persian ` , or ` roc ` .
155+ * ` dayPeriod ` : The formatting style used for day periods like "in the morning",
156+ "am", "noon", "n" etc. Values include: ` narrow ` , ` short ` , or ` long ` .
157+ * ` fractionalSecondDigits ` : The number of digits used to represent fractions of
158+ a second (any additional digits are truncated). Values may be: ` 0 ` , ` 1 ` , ` 2 ` ,
159+ or ` 3 ` .
160+ * ` hour12 ` : If ` true ` , ` hourCycle ` will be ` h12 ` , if ` false ` , ` hourCycle ` will
161+ be ` h23 ` . This property overrides any value set by ` hourCycle ` .
162+ * ` hourCycle ` : The hour cycle to use. Values include: ` h11 ` , ` h12 ` , ` h23 ` , and
163+ ` h24 ` . If specified, this property overrides the ` hc ` property of the locale's
164+ language tag. The ` hour12 ` property takes precedence over this value.
165+ * ` numberingSystem ` : The numeral system to use. Possible values include: ` arab ` ,
166+ ` arabext ` , ` armn ` , ` armnlow ` , ` bali ` , ` beng ` , ` brah ` , ` cakm ` , ` cham ` , ` deva ` ,
167+ ` diak ` , ` ethi ` , ` finance ` , ` fullwide ` , ` geor ` , ` gong ` , ` gonm ` , ` grek ` , ` greklow ` ,
168+ ` gujr ` , ` guru ` , ` hanidays ` , ` hanidec ` , ` hans ` , ` hansfin ` , ` hant ` , ` hantfin ` ,
169+ ` hebr ` , ` hmnp ` , ` java ` , ` jpan ` , ` jpanfin ` , ` jpanyear ` , ` kali ` , ` khmr ` , ` knda ` ,
170+ ` lana ` , ` lanatham ` , ` laoo ` , ` lepc ` , ` limb ` , ` mlym ` , ` mong ` , ` mtei ` , ` mymr ` ,
171+ ` mymrshan ` , ` native ` , ` nkoo ` , ` olck ` , ` orya ` , ` osma ` , ` rohg ` , ` roman ` , ` romanlow ` ,
172+ ` saur ` , ` shrd ` , ` sora ` , ` sund ` , ` takr ` , ` talu ` , ` taml ` , ` tamldec ` , ` telu ` ,
173+ ` thai ` , ` tibt ` , ` tnsa ` , ` traditional ` , ` vaii ` , or ` wcho ` .
174+ * ` timeZoneName ` : An indicator for how to format the localized representation of
175+ the time zone name. Values include: ` long ` , ` short ` , ` shortOffset ` , ` longOffset ` ,
176+ ` shortGeneric ` , or ` longGeneric ` .
177+ * ` timeZone ` : The time zone to use. The default is the system's default time zone
178+ (see [ date_default_timezone_set()] ( https://www.php.net/date_default_timezone_set ) ).
179+ You may use the zone names of the [ IANA time zone database] ( https://www.iana.org/time-zones ) ,
180+ such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
181+
85182### Rich Text Formatting (Use of Tags in Messages)
86183
87184While the ICU message syntax does not prohibit the use of HTML tags in formatted
0 commit comments