Back to Top

How To convert DATE in other language in PHP

How To convert DATE in other language in PHP

WordPress contain language files that hold all of the messages and labels to translate into language.To convert text in another language is very easy in WordPress using the and also you can use multiple language translations.

I was developing WordPress application which language was not English and I wanted the date in another language.Specifically a month name and In that I want to localized month name and WordPress inbuilt functions does not support localized date format.

We can just simply handled this date issue with the use of setlocale() function.

Basic SYNTAX of setlocale

Parameters

$category : To convert a date into other language ,you need to set category parameter and its LC_TIME for date and time formatting with strftime() function

$locale : it’s for a different possible locale names

Let’s take one example which shows the difference if you switch from US locale (standard) to German locale.

Above function may solve your issue with month names returned by the PHP date() function but produces much bigger and sometimes hidden problems.

It creates problems like, it may convert decimal float value into string values that can affect some calculation of site.

Here are the few more articles which you might like

Convert 12-hour datetime to 24-hour datetime in JavaScript
To create multiple date picker using jQuery

Once we set a locale, all the calls to the translator function will return strings according to the set locale value and we can set it with the use of strftime function.

Basic SYNTAX of strftime

Parameters

$category : format of the date you want
$locale : Here you require to pass timestamp so if you have date pass date with strtotime.

So, Let’s see one example for strftime which display date according to setlocale language

strong>NOTE: The locale information(setlocale) is maintained per process, not per thread so maybe it is not working with your windows OS in the local server. If its not work with the local server, try it with the live server.

Comments (2)

  1. That’s what we’ve all been waiting for! Great potsnig!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to convert Object to array in PHP

Posted on 8 years ago

Bhumi

Understanding CSS3 Pseudo-elements

Posted on 8 years ago

Bhumi

How to Animate SVG Image with example

Posted on 9 years ago

Bhumi