Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Date and time format

edited May 2012 in Framework

Hello, please, is it possible to define date and time format for different languages? This formats should be used globally on frontend and backend. I see, there are some datetime function in I18n class, but with fixed format.

Thank you :).


  • It looks like I would need to add a date_format and short_date_format field to the add/edit language forms, and to the lang/languages.php file. Then I could read those settings in apps/admin/handlers/util/dates.php which passes them to jQuery.localize().

    Does there need to be a time format as well do you think?

    The format will be different than regular PHP then too (listed here). But since it's using JavaScript to render the dates, I could show a preview more easily too :)

  • Well, I think time format could be useful too - at least because of choice from 12 or 24 hour format.

    But the jquery.localize.js format could be little problem, because I would like to use this format all around the website. For example Blog application Post listing and Post detail should use this format, or the Events app (date formats are hardcoded here).

    My idea was to have single place to configure all these date formats. So the format should be usable in PHP too. Maybe different configuration for jquery and different for PHP? Or some configuration wrapper? I'm discussing it here mainly because I would like to do it in way which could be used in upstream too.

  • I'll add a time_format too then :)

    Using jquery.localize shouldn't be a problem, because you can use the steps here in any app to output the dates through jquery.localize. Updating this will also localize them anywhere those are used. Some of the apps still need to be updated to use that though.

    I've created an issue on GitHub so I remember to do this here:

  • Great :).

    Maybe I will consider some kind of wrapper from the jquery format string to the PHP compatible variant.

    I mean if there will be possibility to use the configuration from language.php in PHP's date() too, there could be avoided the jquery.localize.js usage in frontend. Or at least, it could be optional, which I will personally preffer :).

  • Why I ended up using jquery.jocalize instead of date() or strftime() is that PHP doesn't know the user's timezone. Dates are always stored in UTC so they can be adjusted to the current user's timezone, but PHP can't do it without using an IP address geolocation service, which would be slow, or by relying on an existing cookie being set from a previous page request.

    So instead, it outputs the date wrapped in a <time> tag that gets converted to the current timezone in the browser, and once it's converted you can also correctly format it for display.

  • edited May 2012

    Yeah, <time> is nice one :). But still, in I18n::_date there is $format parameter, so I think it will be nice to have desired localized format here instead of current defaults, JS still could do the TZ adjustments. But it sure is just small detail, no big deal ;).

  • I've committed changes to add date formats via Tools > Languages now. It provides a format reference and live preview as you customize the formats :)

    A converter between that and PHP's date() or strftime() formats is probably not too hard, but this should cover most cases nicely for now. I've also updated the blog posts so they're now localized properly too.

Sign In or Register to comment.