0

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

2 Answers 2

1

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()

1
  • date_i18n() is correct indeed, but should be noted that it does not accept a Unix timestamp (which it is wrongly documented to), it expects WP's idea of timestamp — offset with a time zone.
    – Rarst
    Commented Oct 16, 2017 at 8:32
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.