How to setup language of a date in a plugin

I am working on a Wordpress theme using a template to manage sports team, matches, players, etc.

I settled my local wordpress time in French. In the blog part, no problem the post are displaying date in French.

But there is a all part with custom post types managed by a plugin. The dates displayed by this plugins remains in English.

By checking the code, I can see the date part formatting is managed here :

function team_get_match_start($match_id, $format = 'j F Y / G:i') {

$date_start = get_post_meta($match_id, '_date_start', true);
if (!$date_start || !strtotime($date_start)) {
    return '';
}

$timezone_string = get_option('timezone_string');
$gmt_offset = get_option('gmt_offset');
if ($timezone_string) {
    $tz = $timezone_string;
} else if ($gmt_offset  0) {
    $tz = date('+Hi', abs($gmt_offset) * 3600);
} else if ($gmt_offset  0) {
    $tz = date('-Hi', abs($gmt_offset) * 3600);
} else {
    $tz = 'UTC';
}

$datetime = date_create( $date_start, new DateTimeZone($tz));
return $datetime-format( $format );

So, this displays me 28 JULY 2017 / 13:00. I would like it to be in french.

I did many unsuccessful tries with strftime(). I am reading about date_i18n() wordpress function, but I am not sure about what to do with it.

Anyone as an idea that could help me ?

Cheers guys

Topic language date-time Wordpress

Category Web


If you have a Unix timestamp, you can use wp_date function to retrieve date in localized format. wp_date is intended to replace date_i18n().

wp_date( get_option( 'date_format' ), get_post_timestamp() );

Ref: wp_date() Credit: Marc Heatley


You need to grab the WordPress date option on the first parameter of date_i18n function :

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

You can see this example in the function codex page : date_i18n()

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.