Featured Articles

my Video Poster 2 (For WordPress blogs)

Add video content to your blogs, many cool features such as post layout templating, automatic commen[...]

WordPress 3.0 Multisite Search

A quick and simple solution for displaying search results from all subblogs on your WordPress 3 Mult[...]

WPDT: date_i18n Function Reference and Usage

by Lars Koudal on 25/06/2009

66 views so far.

Share

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.

Popular Searches
date_i18n, wordpress date_i18n, php date_i18n, date_i18n Wordpress, date_i18n example, date_i18n php, wordpress date_i18n(), wordpress how to use date_i18n function, date_i18n date format, date_i18n wordpress example, date_i18n(), echo date_i18n, wp_locale howto, date_i18n Time wordpress, wordpress blog date svenska, Function Reference wp e-commerce, date_i18n examples, wordpress themes date_i18n, wordpress the_date i18n, date_i18n example wordpress, wordpress date date_i18n, wordpress get the time date_i18n, date_i18n "wordpress",

{ 1 trackback }

{ 3 comments… read them below or add one }

Sapan July 24, 2009 at 10:54

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.

Reply

myWordPress July 25, 2009 at 00:20

Hi Sapan

I use the WP Greet Box for that functionality … http://wordpress.org/extend/plugins/wp-greet-box/

Remember to read one of my first posts here on this blog, http://mywordpress.com/optimize-the-wp-greet-box-plugin-for-better-seo/, for better SEO with WP Greet Box.

Thank you for visiting! :-)

Reply

Sapan July 25, 2009 at 22:55

Thanks a lot… :)

Reply

Leave a Comment

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

Previous post:

Next post: