DateTime::format and strftime

2019-05-11 23:18发布

问题:

I have $date = $run['at']; which gives me 2013-06-03T16:52:24Z (from a JSON input). To transform it to get for example "d M Y, H:i" I use

$date = new DateTime($run['at']);
echo $date->format('d M Y, H:i');

Problem is I need the date in italian. And the only function that supports set_locale is strftime. How can I "wrap" DateTime::format with strftime (or replace, dunno)?

回答1:

setlocale(LC_TIME, 'it_IT.UTF-8');
$date = new DateTime($run['at']);
strftime("%d %B", $date->getTimestamp())

... worked. :)



回答2:

I believe the "proper" way should be using DateTimeZone