2

我得到了这个变量:

$payments['date'] = 21062013

问题:

它是一个日期,所以我想在这个字符串中添加斜杠。

我是如何尝试的:

echo $paymentdate = substr($payments['date'],2)+/+substr($payments['date'],4)+/substr($payments['date'],8);

打不开,有大神帮忙吗?

我的完整代码:

$i = 0;
foreach($SQL->query('SELECT id, form, email, value, data, date, compensated from payments where compensated="N"') as $payments)
{
 $i++;
 $paymentdate = substr($payments['date'], 0, 2)."/".substr($payments['date'], 2, 2)."/".substr($payments['date'], 2, 8);
 echo '<tr bgcolor="' . (is_int($i / 2) ? $config['site']['darkborder'] : $config['site']['lightborder']) . '">  
  <td>' . $payments['id'] . '</td>
  <td>' . $payments['form'] . '</td>
  <td>' . $payments['email'] . '</td>
  <td>' . $payments['value'] . '</td>
  <td>' . $paymentdate .'</td>
  <td>' . $payments['data'] . '</td>
  <td>' . $payments['compensated'] . '</td>
  <td>a</td>
 </tr>';
}
4

4 回答 4

2

使用strtotime()函数来改变它的显示方式。

<?php echo date("m/d/y", strtotime("20130621")); ?>
于 2013-06-21T13:20:19.450 回答
2

这应该适合你;

echo $paymentdate = substr($payments['date'], 0, 2)."/".substr($payments['date'], 2, 2)."/".substr($payments['date'], 4, 4);
于 2013-06-21T13:22:42.093 回答
1

请 :

substr($payments['date'], 0, 2) . '/' . substr($payments['date'], 2, 2) . '/' . substr($payments['date'], 4, 4);

于 2013-06-21T13:23:13.890 回答
0
function convertDate($date, $format = 1)
{
    $newDate = "";

   //Convert a string to an array
   $num = str_split($date);

   switch(format)
   {
     case 1:
        $newDate = $num[0].$num[1]."/".$num[2].$num[3]."/".$num[4].$num[5].$num[6]$num[7] ;
        Break;

        // .... 
   }

 return $newDate;
}
于 2013-06-21T14:24:25.567 回答