Date Function Output in a Local Language

Date function output in a local language

date() is not locale-aware. You should use strftime() and its format specifiers to output locale-aware dates (from the date() PHP manual):

To format dates in other languages,
you should use the setlocale() and
strftime() functions instead of
date().

Regarding Anti Veeranna's comment: he is absolutely right, since you have to be very careful with setting locales as they are sometimes not limited to the current script scope. The best way would be:

$oldLocale = setlocale(LC_TIME, 'it_IT');
echo utf8_encode( strftime("%a %d %b %Y", $row['eventtime']) );
setlocale(LC_TIME, $oldLocale);

PHP date() in foreign languages - e.g. Mar 25 Aoû 09

I think you can't get away from doing so without setting LOCALE:

<?php
setlocale(LC_ALL, 'fr_FR');

echo strftime("%A %e %B %Y");
?>

Some details on strftime:
http://us2.php.net/manual/en/function.strftime.php

Output php date with the right language

From the manual:

To format dates in other languages, you should use the setlocale() and
strftime() functions instead of date().

So use:

setlocale(LC_ALL, 'ca_FR');
echo strftime("%A, %e %B, %G");

note: the selected locale must also be installed on the server, so check if ca_FR is a installed locale. A lot of linux systems have fr_FR or fr_FR.utf8 as french locale

Translating date to default language or selected language

The following code gives the expected result:

setlocale(LC_ALL, "de_DE.utf8");
$myDate='2016-06-17'; //example
echo strftime("%A, %e %B %Y", date_create($myDate)->getTimestamp());

According to the documentation, strftime arguments are a format string and a timestamp. The second argument you provided is not a timestamp.

PHP date - get name of the months in local language

You should use setlocale():

setlocale(LC_TIME, 'fr_FR');
$month_name = date('F', mktime(0, 0, 0, $i));

In this case it would set it to French. For your case it should be one of the following:

  1. sr_BA - Serbian (Montenegro)
  2. sr_CS - Serbian (Serbia)
  3. sr_ME - Serbian (Serbia and Montenegro)

R converting datetime format in foreign language not working

See here https://github.com/tidyverse/lubridate/issues/781

Sys.setlocale("LC_TIME", "Spanish_Spain.1252")
format <- "%a@%A@%b@%B@%p@"
enc2utf8(unique(format(lubridate:::.date_template, format = format)))
str(lubridate:::.get_locale_regs("Spanish_Spain.1252"))
library(lubridate)

Sys.getlocale("LC_TIME")
[1] "Spanish_Spain.1252"

parse_date_time(fechas, 'ymd HM')
[1] "2016-06-15 08:39:00 UTC" "2016-04-02 08:39:00 UTC" "2016-12-02 08:39:00 UTC"

Change language in date()

Thank you for your answer. i tried setlocale(LC_TIME, 'el_GR.UTF-8'); but nothing happend. I have tried setlocale(LC_ALL, 'greek'); but the greek words are ???????.When i encode page to windows-1253 i can see the month in greek language but this is not a solution. What can i do?

EDIT:
I found the solution

$date_encoded = strftime('%B %Y', $this->selected_date);
$date_encoded = iconv('Windows-1253', 'UTF-8//IGNORE', $date_encoded);

Add months in local language to date function

var $time = "Fri May 04 20:33:17 +0000 2018";

function relative_time(time_value) {
var date = new Date(time_value);
var months= ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio',
'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
return date.getDate()+ ' '+ months[date.getMonth()];
}

relative_time($time);

Does this answer your question?



Related Topics



Leave a reply



Submit