6
votes

Comment formater le plus facilement DateTetime dans PHP?

Pour changer 2009-12-09 13:32:15 TO 09/12/2009


0 commentaires

4 Réponses :



13
votes

ici: xxx


0 commentaires

4
votes

Vous pouvez utiliser strtotime code> pour obtenir l'horodatage de la première date et date Pour le convertir en une chaîne à l'aide du format souhaité. Xxx pré>

et vous obtiendrez: p>

09/12/2009


0 commentaires

0
votes
 $long_date = '2009-12-09 13:32:15';

 $epoch_date = strtotime($long_date);

 $short_date = date('m/d/Y', $epoch_date);
The above is not the shortest way of doing it, but having the long date as an epoch timestamp ensures that you can reuse the original long date to get other date format outputs, like if you wanted to go back and have just the time somewhere else.

0 commentaires