4

I'am trying to change dates locale.For example ive got date variable, 2015/Jun/01, 2015/Jun/19/ 2015/Mar/14 and etc. this variable called $startDate. Im trying to change english to my locale lets say lt_LT. Here is the code which i tried to use:

$startDate = ($start_date ? $start_date->format($df) : '-');
setlocale(LC_ALL, 'lt_LT.UTF-8');
echo strftime($startDate);

But it still prints dates in english, what am i doing wrong?

1
  • 1) what is the result of setlocale()? 2) did you try setting the local before creating the date object?
    – hoss
    Jul 4, 2015 at 16:16

2 Answers 2

5

You need to specify output date format in strftime and also pass the $startDate as timestamp.

$startDate = "2015/Mar/14";
$startDate = strtotime(str_replace('/', '-', $startDate));
setlocale(LC_ALL, 'lt_LT.UTF-8');
echo strftime("%Y/%b/%d", $startDate);

Result

2015/Kov/14

More information about strftime on php.net

0
0

Asume, that lt_LT.UTF-8 is missing on your system, as it's working very well on my system. When using unknown locales, it will print in english too.

When using Debian, try: dpkg-reconfigure locales

2
  • It is known language. Jul 4, 2015 at 15:46
  • so you have other php code which is giving you the correct language output? is it there lt_LT or really lt_LT.UTF-8? Which system are you using? Could you let us know an example content of $startDate after the first line of code?
    – Champion
    Jul 4, 2015 at 16:04

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.