datetime - PHP date format with intl-aware day suffix? -


sorry if dupe - lots of similar questions if find exact answer wouldn't asking :)

note i'm coming .net , php newbie, there may noob-scale errors.

i able output e.g. new datetime('2014-01-01 13:15:00') as: 'wednesday 1st of january 2014 @ 1:15pm' (possible - non-localized) or 'mercredi 1er janvier 2014 à 13h15' (not possible?).

basically, there seems no iso formatting equivalent php's 's' date format specifier, nor there 1 strftime?

the intldateformatter::full comes close - 'wednesday, 1 january' or 'mercredi 1 janvier' not english (or french) - seems closest can get? live without 'on', 'the' , 'at' if had to, ordinal suffixes nice. ('wednesday 1 january' - what's that, beginning poem?)

i did see one example on strftime section comments on php.net addressing issue (which seems suggest issue) - seemed add english suffixes, didn't seem use? i'd simple method takes utc datetime, locale , timezone , outputs localized string - preferably in 'proper' human-readable format (as above) possible in english. i'd achieve without writing format string every language in world. nice if worked on windows dev box *nix production box.

<?php $utcdate = new datetime('2014-01-01 13:15:00', new datetimezone('utc')); echo $utcdate->format('l \t\h\e js \o\f f y \a\t g:ia') . "<br>"; function dumpdates($date, $locale, $tz){     $date->settimezone(new datetimezone($tz));     $fmt = new intldateformatter( $locale, intldateformatter::full, intldateformatter::full,          $tz, intldateformatter::gregorian  );     echo $fmt->format($date) . "<br>";     // doesn't work under windows?     setlocale(lc_time, $locale);     echo strftime('%a, %#d %b %y %i:%m:%s %p', $date->gettimestamp()) . "<br>";  } dumpdates($utcdate, 'en_gb', 'europe/london'); dumpdates($utcdate, 'de_de', 'europe/berlin'); dumpdates($utcdate, 'fr_fr', 'europe/paris'); ?> 

the full part of question - including full grammatical legibility - difficult without either, say, writing format string every language in world, or finding library contains such strings. momentjs seems provide great intl support, after cursory search, haven't been able find php equivalent, other intl extension.

you stage of providing internationalised form including ordinal-based number using combination of intldateformatter , numberformatter, first using numberformatter pattern date's ordinal suffix/prefix:

$numfmt = new numberformatter('fr_fr', numberformatter::ordinal); $ordinalday = $numfmt->format($date->format('j')); 

you create intldateformatter allows retrieve pattern full date format of target language:

$dateformat = new intldateformatter('fr_fr', intldateformatter::full, intldateformatter::full, $tz, intldateformatter::gregorian); $datepattern = $dateformat->getpattern(); 

finally, need replace section in $datepattern representing day escaped ordinal day pattern:

$datepattern = preg_replace('/d+', "'"+$ordinalday+"'", $datepattern); $dateformat->setpattern($datepattern); $outputdate = $dateformat->format($date);    

note pattern used intldateformatter different usual php date formatting format codes, here documentation codes recognised.

a warning; in internationalised formats rigidly standardized, ordinal number out of place. example in chinese, format is:

y年m月d日eeee 

and inserting ordinal prefix exists written chinese before day value may odd chinese reader.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -