pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <i id='6jlcx'><tr id='6jlcx'><dt id='6jlcx'><q id='6jlcx'><span id='6jlcx'><b id='6jlcx'><form id='6jlcx'><ins id='6jlcx'></ins><ul id='6jlcx'></ul><sub id='6jlcx'></sub></form><legend id='6jlcx'></legend><bdo id='6jlcx'><pre id='6jlcx'><center id='6jlcx'></center></pre></bdo></b><th id='6jlcx'></th></span></q></dt></tr></i><div class="pntw7bg" id='6jlcx'><tfoot id='6jlcx'></tfoot><dl id='6jlcx'><fieldset id='6jlcx'></fieldset></dl></div>

      <small id='6jlcx'></small><noframes id='6jlcx'>

        <bdo id='6jlcx'></bdo><ul id='6jlcx'></ul>
      1. <legend id='6jlcx'><style id='6jlcx'><dir id='6jlcx'><q id='6jlcx'></q></dir></style></legend>

      2. <tfoot id='6jlcx'></tfoot>

        如何更新 Laravel Eloquent 管理的時(shí)間戳(created_at 和

        How to update the timezone for the timestamps (created_at and updated_at) managed by Laravel Eloquent?(如何更新 Laravel Eloquent 管理的時(shí)間戳(created_at 和 updated_at)的時(shí)區(qū)?)
          <tbody id='iphjL'></tbody>
          <legend id='iphjL'><style id='iphjL'><dir id='iphjL'><q id='iphjL'></q></dir></style></legend>
        1. <tfoot id='iphjL'></tfoot>

                <small id='iphjL'></small><noframes id='iphjL'>

                <i id='iphjL'><tr id='iphjL'><dt id='iphjL'><q id='iphjL'><span id='iphjL'><b id='iphjL'><form id='iphjL'><ins id='iphjL'></ins><ul id='iphjL'></ul><sub id='iphjL'></sub></form><legend id='iphjL'></legend><bdo id='iphjL'><pre id='iphjL'><center id='iphjL'></center></pre></bdo></b><th id='iphjL'></th></span></q></dt></tr></i><div class="3ahtsu2" id='iphjL'><tfoot id='iphjL'></tfoot><dl id='iphjL'><fieldset id='iphjL'></fieldset></dl></div>

                  <bdo id='iphjL'></bdo><ul id='iphjL'></ul>
                • 本文介紹了如何更新 Laravel Eloquent 管理的時(shí)間戳(created_at 和 updated_at)的時(shí)區(qū)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我在 GMT 中有一臺(tái)服務(wù)器,但我想更新這些字段( *created_at* 和 *updated_at* )以在 PST 中保存時(shí)間戳.

                  I have a server in GMT but I want to update those fields ( *created_at* and *updated_at* ) to save timestamps in PST.

                  我已經(jīng)做了一些嘗試來(lái)實(shí)現(xiàn)這一點(diǎn),但沒(méi)有一個(gè)是正確的.

                  I've already did some tests trying to accomplish this but none of them were correct.

                  • 我將 config/application.php 更新為 'timezone' => 'America/Los_Angeles'
                  • 也在服務(wù)器中,我將 php.ini 中的 date.timezone 更改為 'America/Los_Angeles'
                  • I update the config/application.php to 'timezone' => 'America/Los_Angeles'
                  • Also in the server I've change the date.timezone in php.ini to 'America/Los_Angeles'

                  但是任何這些更新都會(huì)將時(shí)區(qū)更新應(yīng)用于 Laravel Eloquent 時(shí)間戳.這個(gè)字段 created_at 和 updated_at 由 Eloquent 處理.

                  But any of this updates apply timezone update to the Laravel Eloquent timestamps. This fields created_at and updated_at are handle by Eloquent.

                  我還使用 sudo dpkg-reconfigure tzdata 更新了 Ubuntu 服務(wù)器時(shí)區(qū),但此更新根本不起作用.

                  I've also update the Ubuntu server timezone using sudo dpkg-reconfigure tzdata but this update didn't work at all.

                  我需要讓 Laravel Eloquent 時(shí)間戳在 PST 時(shí)區(qū)工作,以便將期貨插入數(shù)據(jù)庫(kù).

                  I need to have the Laravel Eloquent timestamps working on PST timezone for futures inserts to the DB.

                  任何幫助都會(huì)有用.謝謝.

                  Any help will be useful. Thanks.

                  推薦答案

                  我知道這個(gè)問(wèn)題有點(diǎn)過(guò)時(shí),但我在嘗試提出相同的解決方案時(shí)偶然發(fā)現(xiàn)了它,并想分享我是如何解決的

                  I know this question is a bit dated, but I stumbled upon it when trying to come up with the same solution, and wanted to share how I went about solving it.

                  我的建議是不要更改存儲(chǔ)消息的時(shí)區(qū).將它們作為 UTC 存儲(chǔ)在數(shù)據(jù)庫(kù)中.將您的存儲(chǔ)設(shè)置為一個(gè)恒定的參考框架,然后將其轉(zhuǎn)換為您需要顯示的任何時(shí)區(qū),從長(zhǎng)遠(yuǎn)來(lái)看,這將為您省去很多麻煩.

                  My advice would be not to change the timezone that the messages are stored in. Store them in the database as UTC. Keeping your storage set to a constant frame of reference and then converting it to whatever timezone you need it displayed in will save you loads of headache over the long run.

                  舉一個(gè)令人頭疼的例子,假設(shè)兩個(gè)人試圖在不同的時(shí)區(qū)協(xié)調(diào)會(huì)議時(shí)間,其中一個(gè)遵守夏令時(shí),另一個(gè)沒(méi)有,您需要以每個(gè)用戶的當(dāng)?shù)貢r(shí)間顯示時(shí)間.將您存儲(chǔ)的 PDT 時(shí)間轉(zhuǎn)換為美洲/開(kāi)曼群島(不遵守夏令時(shí))有多難?當(dāng)時(shí)間存儲(chǔ)在 PST 與 PDT 中時(shí),您會(huì)如何考慮?你怎么知道的?(提示:如果沒(méi)有數(shù)百行額外的代碼來(lái)回答這個(gè)問(wèn)題,你不會(huì)).

                  As an example of one of those headaches, imagine two people trying to coordinate a meeting time in different timezones where one observes DST and one doesn't and you need to display the time in each user's local time. How hard would it be to convert your stored PDT time to say, the America/Cayman (which doesn't observe DST)? And how would you take in account when times are stored in PST vs PDT? How would you know? (Hint: without probably hundreds of lines of extra code just to answer that one question, you won't).

                  要在正確的時(shí)區(qū)獲得超時(shí),只需在模型本身上添加一個(gè) mutator 函數(shù):

                  To get the time out in the correct timezone, simply add a mutator function on the model itself:

                  use CarbonCarbon;
                  
                  class MyModel extends Eloquent
                  {
                      public function getCreatedAtAttribute($value)
                      {
                          return Carbon::createFromTimestamp(strtotime($value))
                              ->timezone('America/Los_Angeles')
                              ->toDateTimeString()
                          ;
                      }
                  }
                  

                  現(xiàn)在,每當(dāng)您執(zhí)行 $myModel->created_at 時(shí),它都會(huì)神奇地轉(zhuǎn)換為正確的時(shí)區(qū),但您仍將 UTC 保留在您的數(shù)據(jù)庫(kù)中,這絕對(duì)比其他時(shí)區(qū)更適合持久存儲(chǔ).

                  Now, whenever you do $myModel->created_at it will magically be converted into the correct timezone, but you still keep UTC in your database which definitely has its perks over other timezones for persistent storage.

                  想讓用戶設(shè)置自己的時(shí)區(qū)?把函數(shù)改成這樣:

                  Want to let users set their own timezones? Change the function to this:

                  public function getCreatedAtAttribute($value)
                  {
                      $user = Auth::user();
                      // If no user is logged in, we'll just default to the 
                      // application's timezone
                      $timezone = $user ? $user->timezone : Config::get('app.timezone');
                  
                      return Carbon::createFromTimestamp(strtotime($value))
                          ->timezone($timezone)
                          // Leave this part off if you want to keep the property as 
                          // a Carbon object rather than always just returning a string
                          ->toDateTimeString()
                      ;
                  }
                  

                  改變時(shí)區(qū)的所有復(fù)雜性,無(wú)論是否考慮夏令時(shí),都從您身上抽象出來(lái),您甚至可以忘記它甚至必須發(fā)生.

                  And all of the complexity of changing timezones, taking daylight savings into account or not is abstracted away from you and you can forget that it even has to happen.

                  有關(guān) Laravel 修改器/訪問(wèn)器的更多信息,請(qǐng)查看文檔.

                  For more information about Laravel mutators / accessors, checkout the documentation.

                  這篇關(guān)于如何更新 Laravel Eloquent 管理的時(shí)間戳(created_at 和 updated_at)的時(shí)區(qū)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語(yǔ)句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無(wú)法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問(wèn)被拒絕)
                      • <bdo id='Nzbpb'></bdo><ul id='Nzbpb'></ul>

                      • <tfoot id='Nzbpb'></tfoot>
                        <legend id='Nzbpb'><style id='Nzbpb'><dir id='Nzbpb'><q id='Nzbpb'></q></dir></style></legend>

                          <tbody id='Nzbpb'></tbody>

                        <small id='Nzbpb'></small><noframes id='Nzbpb'>

                        <i id='Nzbpb'><tr id='Nzbpb'><dt id='Nzbpb'><q id='Nzbpb'><span id='Nzbpb'><b id='Nzbpb'><form id='Nzbpb'><ins id='Nzbpb'></ins><ul id='Nzbpb'></ul><sub id='Nzbpb'></sub></form><legend id='Nzbpb'></legend><bdo id='Nzbpb'><pre id='Nzbpb'><center id='Nzbpb'></center></pre></bdo></b><th id='Nzbpb'></th></span></q></dt></tr></i><div class="xa3vl2t" id='Nzbpb'><tfoot id='Nzbpb'></tfoot><dl id='Nzbpb'><fieldset id='Nzbpb'></fieldset></dl></div>

                            主站蜘蛛池模板: 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 联系我们-腾龙公司上分客服微信19116098882 | 好杂志网-首页 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 浙江建筑资质代办_二级房建_市政_电力_安许_劳务资质办理公司 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 明渠式紫外线杀菌器-紫外线消毒器厂家-定州市优威环保 | 艺术生文化课培训|艺术生文化课辅导冲刺-济南启迪学校 | 北京易通慧公司从事北京网站优化,北京网络推广、网站建设一站式服务商-北京网站优化公司 | 二手Sciex液质联用仪-岛津气质联用仪-二手安捷伦气质联用仪-上海隐智科学仪器有限公司 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 精密模具制造,注塑加工,吹塑和吹瓶加工,EPS泡沫包装生产 - 济南兴田塑胶有限公司 | 成都热收缩包装机_袖口式膜包机_高速塑封机价格_全自动封切机器_大型套膜机厂家 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | PCB接线端子_栅板式端子_线路板连接器_端子排生产厂家-置恒电气 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | 包塑丝_高铁绑丝_地暖绑丝_涂塑丝_塑料皮铁丝_河北创筹金属丝网制品有限公司 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 昆明化妆培训-纹绣美甲-美容美牙培训-昆明博澜培训学校 | 移动机器人产业联盟官网| 集菌仪厂家_全封闭_封闭式_智能智能集菌仪厂家-上海郓曹 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 水厂自动化-水厂控制系统-泵站自动化|控制系统-闸门自动化控制-济南华通中控科技有限公司 | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 警方提醒:赣州约炮论坛真的安全吗?2025年新手必看的网络交友防坑指南 | 烟台螺纹,烟台H型钢,烟台钢材,烟台角钢-烟台市正丰金属材料有限公司 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 | 全自动固相萃取仪_高通量真空平行浓缩仪-勤业永为 | 铁素体测量仪/检测仪/铁素体含量测试仪-苏州圣光仪器有限公司 | 防爆大气采样器-防爆粉尘采样器-金属粉尘及其化合物采样器-首页|盐城银河科技有限公司 | 泵阀展|阀门展|水泵展|流体机械展 -2025上海国际泵管阀展览会flowtech china | 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 | 蒸压釜-陶粒板隔墙板蒸压釜-山东鑫泰鑫智能装备有限公司 | 液压升降货梯_导轨式升降货梯厂家_升降货梯厂家-河南东圣升降设备有限公司 | 精密五金冲压件_深圳五金冲压厂_钣金加工厂_五金模具加工-诚瑞丰科技股份有限公司 | 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 |