gpt4 book ai didi

ruby-on-rails - 几号?使用Elasticsearch和Tire困于45,338年

转载 作者:行者123 更新时间:2023-12-03 02:09:15 26 4
gpt4 key购买 nike

我在Rails4应用程序中使用Elasticsearch和Tire,却迷失了整个日期。

创建了一个构面后:

facet('timeline') { date   :created_at, :interval => 'day' }

直到我获取数据并最终得到:
= @device.facets["timeline"]
> {"_type"=>"date_histogram", "entries"=>[{"time"=>1361232000000, "count"=>1}, {"time"=>1361318400000, "count"=>14}, {"time"=>1361404800000, "count"=>1}

我尝试格式化映射中的日期,但这是不对的:
indexes :created_at, type: 'date', :date_formats => 'basic_date'

我已经阅读了有关yoda时间等的文档,但是我不知道如何将其格式化为合理的格式。目前在Ruby中进行转换使我有以下时间:
45338-06-13 01:00:00 +0100 :(

http://www.elasticsearch.org/guide/reference/mapping/date-format/

最佳答案

您必须将Elasticsearch返回的时间戳除以1000,因为它使用了不同的时间戳表示形式:

Time.at( 1361232000000 / 1000 )

在StackOverflow上查看以下答案: Convert times created by Javascript's getTime() method to ruby Time objects

关于ruby-on-rails - 几号?使用Elasticsearch和Tire困于45,338年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17970842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com