-3

I have this line

<?php
echo date('H:i, d F Y',strtotime($i->date_start));
?>

Which outputs:

20:24, Saturday, 07 December 2013

How do I translate it to my local language?

PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
user3057167
  • 19
  • 1
  • 6
  • Please show an attempt to solve the problem yourself before your ask here. Here's a link to the PHP manual for the `date` function, it will contain everything you need: http://php.net/manual/en/function.date.php - and `setlocate` for your language: http://php.net/manual/en/function.setlocale.php – scrowler Dec 04 '13 at 19:01
  • I did not found how to translate it, and I do not now the location of the strtotime function to be able to translate it, I only have this line and I don`t know what to try! I suck – user3057167 Dec 04 '13 at 19:03
  • Look up `setlocate`, read the manual for it, and call it above your code. Don't bother with `strtotime` – scrowler Dec 04 '13 at 19:03
  • I also tried translating joomla names for month names with no effect – user3057167 Dec 04 '13 at 19:04
  • How does this http://stackoverflow.com/questions/6988536/strtotime-with-different-languages aswer my question !? – user3057167 Dec 04 '13 at 19:07

1 Answers1

1

You could use str_ireplace with an array of searches and an array of replacements.

$monthsDaysEn = array('January','February','March','Saturday','etc'); //populate with all months/days you want translated
$monthsDaysEs = array('enero','febero','marzo','Sabado','etc'); //populate in same order with their counterparts

$datestr = "20:24, Saturday, 07 March 2013";

$translated = str_ireplace($monthsEn,$monthsEs,$datestr);

echo $translated;
JustinM151
  • 744
  • 3
  • 11
  • I tried this `get('date_format','Y-m-d H:i:s'),strftime($i->date_mod)); ?>` nad it does not work... – user3057167 Dec 04 '13 at 19:16
  • If you don't want the headache of trying to get setlocal to work this solution is quite good. –  Feb 01 '20 at 21:20
  • Just a correction - you are using $monthsDaysEn when declaring you variable but $monthsEn later in str_ireplace, it should be the same. –  Feb 01 '20 at 21:30