Use International PHP dates with intl in Date time function bitrix

Рейтинг: 0  
Новая
Предложил Пользователь 262839 24.08.2016 09:53:09

Use International PHP dates with intl in Date time function bitrix

The default uses clause Intl By the  Gregorian-in calendar  But IT CAN Also the make use of OTHER calendars by Specifying a fifth parameter in the calls to IntlDateFormatterconstructor. So by default the previous example would include a calendar specification like the following.

$ DateTime = new DateTime ();
$ IntlDateFormatter = new IntlDateFormatter ( 'es_ES', IntlDateFormatter :: FULL, IntlDateFormatter :: FULL, 'Australia / Yancowinna', IntlDateFormatter :: GREGORIAN);
echo $ IntlDateFormatter-> format ($ DateTime ); // Martes, 21 de julio de 2015, 11:12:43 p.m. (Hora estándar de central Australia)


Should you wish to use another-in calendar IT CAN the BE specified 'as with the part of the locale. The the following example with In I of have Decided to use the  Buddhist-in calendar .

$ A DateTime = new a DateTime ();
$ IntlDateFormatter = new IntlDateFormatter ( 'es_ES @ calendar = buddhist', IntlDateFormatter :: FULL, IntlDateFormatter :: FULL, 'Australia / Yancowinna', IntlDateFormatter :: TRADITIONAL);
echo $ IntlDateFormatter-> format ($ DateTime ); // Martes, 21 de julio de 2558 the BE, 11:16:08 p.m. (Hora estándar de central Australia)


Notice The That I of the below code have changed the locale for the (first parameter) toes_ES = @-in calendar and the buddhist-in calendar (fifth parameter) toIntlDateFormatter :: TRADITIONAL.


Calendars of The  the ICU  Allows you to-play with the include:
  • Japanese ( @calendar=japanese)
  • Buddhist ( @calendar=buddhist)
  • Chinese ( @calendar=chinese)
  • Persian ( @calendar=persian)
  • Indian ( @calendar=indian)
  • Islamic ( @calendar=islamic)
  • Hebrew ( @calendar=hebrew)
  • Coptic ( @calendar=coptic)
  • Ethiopic ( @calendar=ethiopic)
So there you have it; localised time zone aware dates with PHP on multiple calendar types. If the provided formats suit your application then this is a simple way to ensure your date and time information is readable in various locations and languages.