久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    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="qwawimqqmiuu" 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 管理的時間戳(created_at 和

        How to update the timezone for the timestamps (created_at and updated_at) managed by Laravel Eloquent?(如何更新 Laravel Eloquent 管理的時間戳(created_at 和 updated_at)的時區?)
          <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="qwawimqqmiuu" 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 管理的時間戳(created_at 和 updated_at)的時區?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  我已經做了一些嘗試來實現這一點,但沒有一個是正確的.

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

                  • 我將 config/application.php 更新為 'timezone' => 'America/Los_Angeles'
                  • 也在服務器中,我將 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'

                  但是任何這些更新都會將時區更新應用于 Laravel Eloquent 時間戳.這個字段 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 服務器時區,但此更新根本不起作用.

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

                  我需要讓 Laravel Eloquent 時間戳在 PST 時區工作,以便將期貨插入數據庫.

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

                  任何幫助都會有用.謝謝.

                  Any help will be useful. Thanks.

                  推薦答案

                  我知道這個問題有點過時,但我在嘗試提出相同的解決方案時偶然發現了它,并想分享我是如何解決的

                  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.

                  我的建議是不要更改存儲消息的時區.將它們作為 UTC 存儲在數據庫中.將您的存儲設置為一個恒定的參考框架,然后將其轉換為您需要顯示的任何時區,從長遠來看,這將為您省去很多麻煩.

                  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.

                  舉一個令人頭疼的例子,假設兩個人試圖在不同的時區協調會議時間,其中一個遵守夏令時,另一個沒有,您需要以每個用戶的當地時間顯示時間.將您存儲的 PDT 時間轉換為美洲/開曼群島(不遵守夏令時)有多難?當時間存儲在 PST 與 PDT 中時,您會如何考慮?你怎么知道的?(提示:如果沒有數百行額外的代碼來回答這個問題,你不會).

                  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).

                  要在正確的時區獲得超時,只需在模型本身上添加一個 mutator 函數:

                  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()
                          ;
                      }
                  }
                  

                  現在,每當您執行 $myModel->created_at 時,它都會神奇地轉換為正確的時區,但您仍將 UTC 保留在您的數據庫中,這絕對比其他時區更適合持久存儲.

                  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.

                  想讓用戶設置自己的時區?把函數改成這樣:

                  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()
                      ;
                  }
                  

                  改變時區的所有復雜性,無論是否考慮夏令時,都從您身上抽象出來,您甚至可以忘記它甚至必須發生.

                  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.

                  有關 Laravel 修改器/訪問器的更多信息,請查看文檔.

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

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

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                      • <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="qwawimqqmiuu" id='Nzbpb'><tfoot id='Nzbpb'></tfoot><dl id='Nzbpb'><fieldset id='Nzbpb'></fieldset></dl></div>

                            主站蜘蛛池模板: 国产精品久久久久久久久免费高清 | 久久一二 | 国产精品久久久久999 | 精品视频网| 午夜影院在线观看视频 | 伊人国产精品 | 亚洲福利 | 精品欧美一区二区三区久久久 | 国产精品国产成人国产三级 | 欧美激情在线观看一区二区三区 | 亚洲一区二区精品视频 | 国产精品精品久久久 | 国产激情视频网站 | www日本在线播放 | 日本理论片好看理论片 | 一级全黄少妇性色生活免费看 | 成人av网页| 玖玖视频免费 | 中文字幕一区在线观看视频 | 欧美.com| 免费在线观看成人 | 美国a级毛片免费视频 | 一区中文字幕 | 在线观看中文字幕 | 福利视频网 | 伊人免费观看视频 | 亚洲成人av | av在线一区二区 | 日韩中文电影 | 色黄视频在线 | 亚洲精品www久久久 www.蜜桃av | 久久a久久 | 欧美黄色网 | 国产欧美一区二区三区日本久久久 | 亚洲国产精品视频一区 | 国产精品永久免费 | 天天综合网7799精品 | 久久精品手机视频 | 亚洲自拍偷拍免费视频 | 国产精品毛片无码 | 国产精品二区三区 |