dsh8009271 2016-08-02 19:33
浏览 48

从数据库中提取时的CakePHP日期格式

In my database, date of births are stored as Y-m-d format, for ex. 1965-09-04. When cakePHP is fetching is from the database, its internally converting these date to d/m/y format, so 1965-09-04 becomes 4/9/65.

Now when I try to convert this date to dd/mm/YY format (04/09/1965), it gives (04/09/2065).

Short story, I don't want cakephp to convert date formats while fetching from DB.

  • 写回答

2条回答 默认 最新

  • dqqyp90576 2016-08-02 21:56
    关注

    Found the answer. It was actually formatting date while data was going from controller to the view. Changed default date format of cakephp using bootstrap file. Added this in the file :

    Cake\I18n\Date::setToStringFormat('YYYY-MM-dd');
    Cake\I18n\FrozenDate::setToStringFormat('YYYY-MM-dd');
    
    \Cake\Database\Type::build('date')
        ->useImmutable()
        ->useLocaleParser()
        ->setLocaleFormat('YYYY-MM-dd');
    

    Reference : Cakephp 3.2 change default date format

    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析