doudizhu2222 2017-03-28 11:01
浏览 146

Laravel多个时区

I am trying build a database of user trips, which involves storing:

  • FlightNumber
  • DepartureAirport
  • DepartureTime
  • ArrivalAirport
  • ArrivalTime

Note, that both the airports can be in different timezones. I need to work out the time difference, and number of days to this flight etc.

I am not sure how to approach this problem. Should I add more columns to store local date time, and UTC times?

Also, I have seen that Laravel has dateTimeTz() column type. However it doesn't seem to be storing any information about timezone?

Posts Table:

$table->dateTimeTz('newTime')->nullable();

Setting new time:

$p->newTime = \Carbon\Carbon::now('Asia/Kolkata')
=> Carbon\Carbon {#841
     +"date": "2017-03-28 16:23:33.490926",
     +"timezone_type": 3,
     +"timezone": "Asia/Kolkata",
   }

>>> $p
=> App\Post {#836
     id: 1,
     user_id: 1,
     title: "Et quaerat deserunt qui ullam voluptas.",
     body: "Aut eos id ut qui laborum. Tempore rerum ut quas deserunt voluptas optio.",
     slug: "et-quaerat-deserunt-qui-ullam-voluptas",
     newTime: "2017-03-28 16:23:33",
     created_at: "2017-03-28 10:51:36",
     updated_at: "2017-03-28 10:51:36",
   }
  • 写回答

2条回答 默认 最新

  • duan0531 2017-03-28 12:34
    关注

    Easiest way is to store date and time in UNIX timestamp (it's timezone independent). Then you can convert it to any timezone (depends on user location or airport timezone)

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序