I'm brazilian and there's a wordpress plugin that uses
" . date("d F Y (H:i)",$date) . "
Output: 16 January 2013 (00:54)
But it should be 16 Janeiro 2013 (00:54), in portuguese... How can I change it?
PS: I think maybe the date is set by an external file provided by the plugin creator :p I'm not sure though
WordPress has date_i18n to retrieve the date in localized format, based on timestamp.
Try:
echo date_i18n("d F Y (H:i)", $timestamp);
WordPress has an extensive page on how to format date and time.
For the french language I use this
setlocale(LC_ALL, 'fra');
echo strftime("%A %d %B %Y",time());
For in portuguese
setlocale(LC_ALL, 'ptg'); //
echo strftime("%A %d %B %Y",time());
see Language Strings Country/Region Strings.
The documentation for date already answers this:
To format dates in other languages, you should use the setlocale() and
strftime() functions instead of date().
And strftime says that the way to do what is by using setlocale:
Format the time and/or date according to locale settings. Month and
weekday names and other language-dependent strings respect the current
locale set with setlocale().
That said, the C locale-aware functions do not provide sufficient functionality for languages that have cases. In such situations (i.e. most of the time) you need to roll your own.
Related
I'm a noob (I confess it) and can't manage to find a solution to my problem.
I'm setting up the date format on Drupal and it uses the PHP date format.
Right now it's "d F Y", so it appears as 07 Dicembre 2021 (in Italian), but in Italian months are written out in lowercase. Is there a way to transform Dicembre into dicembre? I couldn't find a proper way.
Thanks for your help!
Using strtolower() the output will be as you expected:
<?php echo strtolower(date("M"),2);?>
So to implement it only for Month, simply break the date format into 3 parts. Day , Month, Year.
Use drupal module:
https://www.drupal.org/project/simple_field_formatter
Go to:
/admin/structure/types/manage/[YOURTYPE]/display
For your date field, click the gearwheel on the right (format settings) and activate the checkbox for strtolower
Or create your own FieldFormatter: https://www.webwash.net/how-to-create-a-custom-field-formatter-in-drupal-8/
You should use the locale aware strftime, which formats according to the current locale.
setlocale(LC_TIME, "it_IT");
echo strftime("%d %B %Y"); // 07 dicembre 2021
I configured my timezone to Europe/Paris in php.ini. When executing date_default_timezone_get() I do get the correct value.
Then, I expect strftime('%x', date()) to output something like 16 novembre 2018 which is the French format. But instead, I get 11/16/2018 which looks like the US format.
Any idea why?
The time zone has no effect on how dates and times are presented, for that you need to set the locale. There are no standards for locale names, but fortunately PHP's setlocale() function will take multiple locale names, stopping at the first successful one.
// just a few common name formats
setlocale(LC_TIME, ["fr_FR.utf8", "fr_FR#euro", "fr_UTF8", "fr_FR", "french"]);
echo strftime("%d %B %Y", time());
I tried:
setlocale(LC_ALL, 'fr_utf8');
echo strftime("%d %B %Y", time());
and got:
16 novembre 2018
after setting the timezone to Europe/Paris, Use echo date('d-M-Y') and it will display your desired time. it worked for me
I have a date field in my table material
id: int;
dat_operation : date;
name : varchar(255);
I would like to know how to translate date format in French
I tried with:
<?php echo date("F j Y",strtotime($var['date_operation']));?>
But i have this result
June 14 2016
First, you'll have to set the "locale information", to specify which language you want to use. Keep in mind, that even though you set that language, it needs to be installed on the server you're running on. It most likely is, but you'll notice if the setlocale has no effect (default is English).
The second thing you'll need to know, is that date() isn't affected by this, you'll have to use strftime() instead, which has a slightly different formatting, which you'll find on the documentation.
An example of using French dates with these two functions:
setlocale(LC_ALL, 'fr_FR');
echo strftime("%B %e %Y", strtotime($var['date_operation']));
Reference and documentation:
http://php.net/manual/en/function.setlocale.php
http://php.net/manual/en/function.strftime.php
The modern and rock-solid approach is the intl (from "Internationalization") extension, which offers e.g. the IntlDateFormatter class:
$date = new DateTime('2016-06-14');
$fmt = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE, 'Europe/Paris', IntlDateFormatter::GREGORIAN);
var_dump($fmt->format($date));
string(12) "14 juin 2016"
If you think it's overkill for your project, you can use the legacy strftime() function but you need to change current locale:
$date = strtotime('2016-06-14');
var_dump(setlocale(LC_TIME, 'fr_FR', 'fr')); // Need to try values until you get true
var_dump(strftime('%B %e %Y', $date));
You need to have French locale data installed. In my experience, this works better on Unix-like systems than on Windows.
I have a column which is a Timestamp.
It records something like: 2010-02-08 12:10:22
Then I use this in php:
$postdate = date( "j F", strtotime( $row['modify_date'] ) );
And it can output something like: 8 February
My Q is, how can I change the date-text so it outputs the month name in another language (swedish specifically)?
Ex: January is in Swedish Januari
Thanks
The native PHP function for that is strftime().
%B Full month name, based on the locale January through December
if the server is not in the swedish locale, use setlocale().
That said, I have had so many troubles with setlocale() in the past, especially on shared hosting, that I tend to keep an array of month names in whatever config file / dictionary file the project has:
$monthnames["de"] = array("Januar", "Februar", "März", "...");
$monthnames["fi"] = array("Tammikuu", "Helmikuu", "...");
echo $monthnames[$language][date("n", strtotime( $row['modify_date'] ))];
If you use setlocale() then you can output locale-specific names via strftime().
I'm using Codeigniter for display dates.
I have this but it's echoed in english, how do I set it to other language? I already have the spanish language pack, but I can't figure it out how to load it.
$this->load->helper('date');
echo mdate("%F %d, %Y", strtotime(now()));
Thanks
// Set locale to Spanish Argentina, change to your installed language
setlocale(LC_TIME, 'es_AR');
echo strftime("%B %d, %Y", time());
First you do not need to use the date helper to accomplish this. mdate() is essentially the same as strftime() where just the vars are slightly different. Also your code strtotime(now()) is wrong. now() is the exact same as time() as indicated in the CI documentation. It returns a UNIX timestamp, strtotime() converts a string to a UNIX timestamp. So what you were doing was trying to convert a timestamp to a timestamp, which of course is wrong. I changed the code so it doesn't require the helper and correctly will output MONTHNAME DATE, YEAR in the specified language. Make sure you change the es_AR to whatever Spanish language you installed. It will be the in the format es_COUNTRYCODE
The traductions dates in "calendar_lang.php"
$this->config->set_item('language', 'spanish');
$this->load->library('calendar');
echo 'Mes:'.$this->calendar->get_month_name(date('m'));
echo 'Día:'.$this->calendar->get_day_names(date('d'));