MariusNV
MariusNV

Reputation: 320

Change php date output language

I am using few variables to store different php dates in desired formats like following:

$today = date('Y-m-d');
$todayPretty = date('d. M');
$oneMonthBefore = date('Y-m-d', strtotime('-1 months'));
$oneMonthBeforePretty = date('d. M', strtotime('-1 months'));
$oneMonthBefore2 = date('Y-m-d', strtotime($this->oneMonthBefore .' -1 day'));
$oneMonthBefore2Pretty = date('d. M', strtotime($this->oneMonthBefore .' -1 day'));
$twoMonthsBefore = date('Y-m-d', strtotime('-2 months'));
$twoMonthsBeforePretty = date('d. M', strtotime('-2 months'));
$currentMonth = date('F');
$previousMonth = date('F', strtotime('-1 months'));

Unfortunately I need them in a different language like danish for example so I've set up the following with no results:

setlocale(LC_ALL, "da_DK.UTF-8");

I've read that I have to use strftime function but how I should approach this when it comes to the variables that doesn't use strtotime in my case? Any help or guidance is more than welcomed.

Upvotes: 1

Views: 1848

Answers (2)

Frank
Frank

Reputation: 2041

At first you should check if you have installed your locale with:

locale -a 

in commandline.

if not you can do that on ubuntu/debian with:

sudo locale-gen da_DK.UTF-8

In PHP you can also trying multiple deff's if your code will develop on windows and deploy on linux, like this:

<?php
setlocale (LC_ALL, 'de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'de', 'ge', 'de_DE.ISO_8859-1', 'German_Germany');

Upvotes: 1

Ajeet Kumar
Ajeet Kumar

Reputation: 815

For Universal:

setlocale(LC_ALL,'nl_NL.UTF-8');

For windows

setlocale(LC_ALL,'nld_nld');

For linux

setlocale(LC_ALL, 'nl_NL');

If this don't work, then you have to create a snippet [[!setlocale]] and put in this:

setlocale(LC_ALL,'nl_NL.UTF-8');

And call this snippet in front of your !DOCTYPE or html call

Upvotes: 1

Related Questions