>Здравствуйте.
>Есть строка - временной штамп в формате yyyymmddhhmmss. Надо разделить его на
>составляющие:
>год, месяц, день, час, минута, секунда. Что я попробовал, не срабатывает:
>
><?php
>$TmStamp='20051103103210';
>echo("Date: $TmStamp<br>\n");
>//0
>$Date=array();
>preg_match('/^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}$/s',$TmStamp,$Date);
>printf("Date: %4s.%2s.%2s, %2s:%2s:%2s<br>\n",$Date[0],$Date[1],$Date[2],$Date[3],$Date[4],$Date[5]);
>//1
>printf("Date: %s<br>\n",date('Y.m.d, H:i:s',strtotime($TmStamp)));
>//2
>printf("Date: %4s.%2s.%2s, %2s:%2s:%2s<br>\n",unpack("A4A2A2A2A2A2",$TmStamp));
>?>
>
>Прошу помощи. Заранее, спасибо.
Заранее используйте поиск в гугле ...
http://www.google.ru/search?hl=ru&q=php+parse+mysql+timestamp&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA+%D0%B2+Google&lr=
<?php
///////////////////////////////////////////////////////////
// mysql_to_unix_time: converts a 14-digit MySQL //////////
// timestamp to a UNIX timestamp //////////////////////////
///////////////////////////////////////////////////////////
/*
$datetime should be a number in the format yyyymmddhhmmss
Returns the date's UNIX timestamp
*/
function mysql_to_unix_time ($datetime) {
// Convert to string so we can reliably parse it
settype($datetime, 'string');
// Break the number up into its components (yyyymmddhhmmss)
// storing results in the array matches
eregi('(....)(..)(..)(..)(..)(..)',$datetime,$matches);
// Pop the first element off the matches array. The first
// element is not a match, but the original string, which
// we don't want.
array_shift ($matches);
// Transfer the values in $matches into labeled variables
foreach (array('year','month','day','hour','minute','second') as
$var) {
$$var = array_shift($matches);
}
return mktime($hour,$minute,$second,$month,$day,$year);
}
$formatdate = date("M/D/Y H:i:s", mysql_to_unix_time("20051103103210"));
echo $formatdate;
?>