想在cakephp 2.0中将时间戳更改为日期

时间:2014-04-04 07:22:42

标签: php mysql datetime timestamp cakephp-2.0

usng finc condition i am getting following result. I want to change the my timestamp to date format . while using find condition .
for example :-  $emailLogDetail= $this->LogEmail->find('all', array(
           'fields' => array(
            'LogEmail.*',
            //'date("m/d/Y", strtotime(LogEmail.TimeStamp)) as Date',           
            'User.email'
        ),
         'order' => 'LogEmail.id DESC',
        'joins' => $joins
    ));

现在我已经评论了日期转换代码因为它给出了错误。但有没有办法在添加选择查询

时将时间戳转换为日期
Array
(
    [0] => Array
        (
            [LogEmail] => Array
                (
                    [Id] => 12
                    [Status] => sent
                    [UserId] => 42
                    [Subject] => Confirmation!
                    [Body] => hiiiii
                    [TimeStamp] => 1395912288
                    [ActionName] => Register
                )

            [User] => Array
                (
                    [email] => test@gmail.com
                )

        )
)

1 个答案:

答案 0 :(得分:0)

使用此

"FROM_UNIXTIME(LogEmail.TimeStamp) as date"

与格式化

"FROM_UNIXTIME(LogEmail.TimeStamp, '%m\%d\%y') as date"

您要求在core.php上存储该格式并在整个应用程序中使用它。我建议你不要采取这种方法......这是 -

在core.php上

配置::写(' dateFormat'," FROM_UNIXTIME(LogEmail.TimeStamp,'%m \%d \%y')作为日期");

现在,您可以从应用程序的任何位置阅读此内容 -

$dateFormat = Configure::read('dateFormat');
$emailLogDetail= $this->LogEmail->find('all', array(
           'fields' => array(
            'LogEmail.*',
            $dateFormat,           
            'User.email'
        ),
         'order' => 'LogEmail.id DESC',
        'joins' => $joins
    ));