On Mon, Jun 25, 2012 at 7:45 AM, Derric Atzrott < datzrott@alizeepathology.com> wrote:
How do you format dates according to user preference in Mediawiki? I presume it has something to do with DateFormatter (http://svn.wikimedia.org/doc/classDateFormatter.html), but I'm not 100% sure how to make use of this class.
Traditionally you would use the date(), time(), or timeanddate() methods on the Language class. These have options on whether to use the defaults or the current user's preferences.
This might usually look like: global $wgLang; $wgLang->timeanddate( $timestamp )
In more recent code if you're working on 1.20 (I'm not sure exactly when it came in), you might use the newer userTimeAndDate() methods which accept an explicit user object -- that lets you format for arbitrary users, sometimes useful for things like mail and always handy in that it's clearly marked. :)
$user = $this->getUser(); $this->getLanguage()->userTimeAndDate( $ts, $user );
-- brion