Extraiga la fecha de la cadena en PHP [duplicado]
Frecuentes
Visto 436 equipos
2 Respuestas
4
$dateTime = DateTime::createFromFormat('D M d Y H:i:s e', 'Mon Mar 25 2013 15:28:21 GMT+0000');
$dateTime->setTimezone(new DateTimeZone('UTC'));
echo $dateTime->format('Y-m-d H:i:s');
Note this requires at least PHP 5.3.0, for more information see documentation at http://www.php.net/manual/en/datetime.createfromformat.php
contestado el 28 de mayo de 14 a las 14:05
Thanks that's fulfils my request completely. THanks - user1369905
@barry-staes - If people are still developing for unsupported PHP versions < 5.3.0 then it is really time for them to upgrade now - Mark Baker
No hay necesidad de ->setTimezone()
since DateTime object is already set to UTC offset. - Glavic
0
Ver http://php.net/manual/en/function.date-parse.php
Example #1 A date_parse() example
<?php print_r(date_parse("2006-12-12 10:00:00.5")); ?>
El ejemplo anterior dará como resultado:
Array ( [year] => 2006 [month] => 12 [day] => 12 [hour] => 10 [minute] => 0 [second] => 0 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array() [error_count] => 0 [errors] => Array() [is_localtime] => )
From here on, you should be able to parse Mon Mar 25 2013 15:28:21 GMT+0000
. O considere usar explode(' ', $parts)
to split it into a $parts[2]='25'
formación.
contestado el 28 de mayo de 14 a las 14:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php datetime or haz tu propia pregunta.
What do you want to do with the date? - iCode
Have you seriously made a basic search before asking ? - BMN
Quiere decir
Mar 25 2013
? - AlbziI want the date in 2013-03-25 15:28:21 format - user1369905