php - 想要将 cakephp 2.0 中的时间戳更改为日期

标签 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
                )

        )
)

最佳答案

使用这个

"FROM_UNIXTIME(LogEmail.TimeStamp) as date"

带格式

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

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

位于 core.php

配置::write('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
    ));

关于php - 想要将 cakephp 2.0 中的时间戳更改为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22856191/

相关文章:

mysql - 查找不同子序列行的日期时间之间的间隙

PHP/MySQL : Why is my database all of the sudden case-sensitive for table names on my Linux server (and not on my XP server)?

php - 如何获取 MySQL 中最后更新行的 ID?

php - 在 HTML 中显示 XML

mysql - 如果我将全局 event_scheduler 关闭,运行事件会发生什么

mysql - 如何通过标签搜索数十亿个项目(寻找最佳架构)?

sql-server - 如何将SQL Server的时间戳列转换为日期时间格式

php - Jenkins 在部署时创建文件而不是符号链接(symbolic link)

php - MySQL 大于 microtime 时间戳

c# - 在 C# 中将总时间转换为分钟