WPDT: date_i18n Function Reference and Usage

WordPress Development Tip

WordPress includes functions to assist in making your WordPress Plugins properly localized. One of the functions is the date_i18n function. This function has no example however, and in this post I will explain how to use it:

To get the information on which settings the blog has, you need to include the wp_locale as a global in the function you use it in:

global $wp_locale;

Now you can get the date format by calling ‘date_format’ via the get_option function like this:

$dateformat=get_option('date_format');

To convert and display a date properly, you can now call the date_i18n-function using the value in the $dateformat variable, along with a unix timestamp as the time you want to display.

Remember you must provide a unix timestamp for the function to return a proper value, and in the following example I convert a date using PHP’s built in function strtotime.

In the example I put all the function calls into one line.

Single Line Example:

echo date_i18n(get_option('date_format') ,strtotime("11/15-1976"));

Depending on your blog settings you will see the date displayed in your local format, for example: 15. november 1976.

  1. [...] fans and users ou&#114&#115&#101lves, we’re always interested to hear about plug&#105&#110&#115 WPDT: date_i18n Function Reference and Usage – mywordpress.co&#109&#10&#486/25/2009 Join the forum discussion on this post – (1) [...]

  2. Sapan says:

    Thanks for the lucid explanation of the function…
    It helped me to solve one of my problems.. :)

    btw, can u pls. tell me which plugin do u use to Welcome the user, i.e. the one which shows ‘Welcome Googler! If you find this page useful, ….’

    Thanks.

PRIVACY POLICY: Your privacy is important to us. We will never sell or rent your email address and you can unsubscribe at any time.

If you check the check-box above and leave a comment, you will sign up to our newsletter, but do not worry, we only send out very few e-mails. We usually only send you an e-mail when we launch a new product, want to touch base with our e-mail readers or we have found a really really cool product we want to tell you about.

line
footer
Powered by Wordpress | Designed by Elegant Themes