PHP DateTime转换

时间:2013-02-08 02:47:02

标签: php datetime

我目前已将 DateTime 存储在数据库中,如下20130208110000所以我需要将其分为两部分,即格式为08/02/2013的日期和此格式的时间11:00 AM,哪个功能有效地做到了这一点?

这是我用来同时加入日期和时间的功能

$startMonth = $this->_getParam('starts_month_day_year');
$startTime = $this->_getParam('starts_time');
date("YmdHis",strtotime($startMonth.$startTime));

2 个答案:

答案 0 :(得分:1)

使用你正在做的事情会有什么问题?

$myDate = "20130208110000";
date("d/m/Y", strtotime($myDate)); // Date, e.g. 08/02/2013
date("h:i A", strtotime($myDate)); // Time, e.g. 11:00 AM

答案 1 :(得分:1)

<?php
      $originalDate = "20130208110000";
      $newDate = date("d-m-Y g:i A", strtotime($originalDate));
      echo $newDate;  //08-02-2013 11:00 AM
?>

其中,

  

g :12小时格式的一小时没有前导零[0到12]

     

:分数为前导零[00到59]

     

A :大写Ante meridiem和Post meridiem [AM或PM]