This thread is resolved. Here is a description of the problem and solution.

Problem: How to change the time format in the code based on the language.?

Solution: Just use if, else condition with ICL language select to show different date format. Please refer : https://wpml.org/forums/topic/php-error-ificl_language_codeen/#post-2111534

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by benW-2 1 year ago.

Assigned support staff: Riffaz.

Author Posts
May 5, 2019 at 10:16 pm #3744057

benW-2

In my theme I have dates in English showing as
F Y
eg April, 2019
but in Chinese language I would like to have
2019年4月 (Year/Month/Day)
instead of
四月2019 ( F Y )

an example line from the theme is:

<span itemprop="dateCreated" class="date entry_date updated"><?php echo get_the_time('F, Y');?> </span>

How can I change the format of dates for different languages?

May 6, 2019 at 12:27 pm #3748263

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

Just use if, else condition with ICL language select to show different date format.
Please refer : https://wpml.org/forums/topic/php-error-ificl_language_codeen/#post-2111534

Let me know how it goes.

Regards,
Riffaz.

May 9, 2019 at 8:40 am #3774253

benW-2

My issue is resolved now. The advice wasn't directly applicable, I had to find an alternative solution that involved editing each occurrence in theme files, as opposed to creating a function, but I got it sorted.
Edited occurrances in theme files, eg
changed
<?php the_time('F Y'); ?>
to
<?php if(ICL_LANGUAGE_CODE=='zh-hans' || ICL_LANGUAGE_CODE=='zh-hant') { the_time('Y 年 n 月'); } else { the_time('F Y'); }?>