date – wp_date doesn’t work

Question

in my original code the date was wrapped with date_formatted. my website is bilingual so i need to localize date format and name of months etc. i’ve changed it with wp_date but it does not work.

the original code. the output of date_format is only english so it is not good for me.

function getDateSF ( $start, $end ) {

    $_start = [ date_format( $start, __('F d', 'my-theme') ), date_format( $start, __('g:i a', 'my-theme') ) ];
    $_end = [ date_format( $end, __('F d', 'my-theme') ), date_format( $end, __('g:i a', 'my-theme') ) ];

    $date="<div class="transl">".$_start[0] .' | '. $_start[1] .'  '. __('to', 'my-theme') .' '. $_end[1] .'</div>';

    if ( date_format( $start, 'Y/m/d' ) != date_format( $end, 'Y/m/d' ) )
        $date="<div class="transl">". $_start[0] .' | '. $_start[1] .' </div><div class="transl"> '. $_end[0] .' | '. $_end[1] .'</div>';

    return $date;
}

wp_date is good for localization but it doesn’t work:

function getDateSF ( $start, $end ) {

    $_start = [ wp_date( __('F d', 'my-theme'), $start ), wp_date( __('g:i a', 'my-theme'),  $start ) ];
    $_end = [ wp_date(  __('F d', 'my-theme'),$end ), wp_date(  __('g:i a', 'my-theme'),$end ) ];

    $date="<div class="transl">".$_start[0] .' | '. $_start[1] .'  '. __('to', 'my-theme') .' '. $_end[1] .'</div>';

    if ( date_format( $start, 'Y/m/d' ) != date_format( $end, 'Y/m/d' ) )
        $date="<div class="transl">". $_start[0] .' | '. $_start[1] .' </div><div class="transl"> '. $_end[0] .' | '. $_end[1] .'</div>';

    return $date;
}

0
okan şahin 2 months 2022-10-11T14:25:57-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse