I want to localize date and time in php. I stored datetime in UTC in my database. And I want to:
- display the time in the correct timezone
- display the time in the correct language
For the first task, I use:
$time = //retrieve from database
$date_obj = new DateTime($time, new DateTimeZone("UTC"));
$date_obj->setTimeZone(new DateTimeZone($timezone));
$display_date = $date_obj->format($format);
It works.
For the second task, after doing some research, it seems that I have to do something like this:
setlocale(LC_TIME, "de_DE"); //only necessary if the locale isn't already set
$formatted_time = strftime("%a %e.%l.%Y", $mytime->getTimestamp())
The problem is I don't know how to do the two things together.
Thank you!