UTC和DateTime结构的Elixir时区比较
我正在尝试比较两个数据,以查看它们是否重叠。但是,一个是dateTime结构,另一个是一个时间 - 这就是它们从数据库中出现的方式。我无法弄清楚如何做到这一点 - 如果我可以在UTC中进行比较并保持时区意识,那就太好了。
我的两次是: start_datetime_1 = 〜U [2022-03-31 11:15:00.000000Z]
和 starttime_2 =#DateTime< 2022-03-31 11:15:00.000000+01:00 BST Europe/London>
我想做类似的事情: datetime.compare(start_datetime_1,start_datetime_2 ==:gt ||:eq)
任何帮助都将不胜感激!
I am trying to compare two datetimes to see if they overlap. However, one is a DateTime struct and the other is a ~U[] time - this is how they come out of the database. I cannot work out how to do this - it would be good if I could compare them both in UTC and also keep the timezone awareness.
The two times I have are:start_datetime_1 = ~U[2022-03-31 11:15:00.000000Z]
andstarttime_2 = #DateTime<2022-03-31 11:15:00.000000+01:00 BST Europe/London>
I wanted to do something like:DateTime.compare(start_datetime_1, start_datetime_2 == :gt || :eq)
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
~U[2022-03-31 11:15:00.000000Z]
与DateTime
相同,但采用UTC
。印记~U[]
只是语法糖。您可以与
DateTime.compare/2
开箱即用。它理解时区。~U[2022-03-31 11:15:00.000000Z]
is the sameDateTime
but inUTC
. A sigil~U[]
is just syntactic sugar.You can do a comparison with
DateTime.compare/2
out of the box. It understands timezones.