Reputation: 265
Fatal: Call to a member function format() on boolean
How can I show the date in current language?
$date = 1496102399;
$date = DateTime::createFromFormat('j F Y',"@$date");
$date = $date->format('Y-m-d');
I want the date to be translatable when using this date format: j F Y
How can I achieve this?
Upvotes: 1
Views: 1797
Reputation: 427
WordPress has inbuilt function date_i18n() to get the date in localized format.
You can try below code:
echo date_i18n("d F Y (H:i:s)", strtotime('2017-05-27 16:08:01')) ;
Upvotes: 0
Reputation: 15141
Do it like this, there are few problems in your code.
Problems:
1.
$end_date
is not initialized. just changing this will also not work. check here2.
DateTime::createFromFormat
expects second parameter to be time string (like this15-Feb-2009
)not timestamp
.
ini_set('display_errors', 1);
$unixtimestamp = 1496102399;
$date = new DateTime();
$date->setTimestamp($unixtimestamp);
echo $end_date = $date->format('Y-m-d');
For displaying the date in Deutsch
language you can use this, prerequisites are listed below of this code doesn't work.
<?php
ini_set('display_errors', 1);
$loc=setlocale(LC_ALL,'de_DE');
echo strftime('%d %B %Y',1496102399);
1.
locale -a
Listing all locale's present on your system, make surede_DE
,de_DE.iso88591
,de_DE.utf8
these locale's are present on your system2.
locale-gen de_DE
3.
dpkg-reconfigure locales
reconfigure locales
Upvotes: 2