Category Archives: PHP

Using local date and time in PHP

If your trying to display your local language, when outputting a date there is an easy way to do exactly this. Don’t use date() as you usually do, this will only output it in English.

Instead you should use the setlocale() function to set your local language when executing your script. Have a look at the PHP manual for more info on this. I’m giving your a brief expample of how to use it when setting the langugage to Danish.

//change output language to danish
setlocale(LC_TIME, 'da_DK');

//outputs Onsdag 03. April 2013
echo (strftime("%A %d. %B %Y"));

There you go, that should help you out. If you have any questions let me know in the comments.