码迷,mamicode.com
首页 > 其他好文 > 详细

mongo的时间类型,erlang中对其的处理

时间:2016-11-04 07:42:47      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:androi   time   简单   time_t   second   end   blog   时间类   发送消息   

需求:要想在一个调度中,从mongo中查出大于一个时间戳的所有的数据总和。

这个需求很简单,一个是scheduler,还有另一个就是查出来大于某个时间戳的总和,比如大于每天0点时间点的和.

需要注意的是:mongo中的date类型以UTC(Coordinated Universal Time)存储,就等于GMT(格林尼治标准时)时间,我们是+8时区,也就是时差相差8,所以+8小时就是系统当前时间.

 

举个栗子:

%% 获取当天的0点时间戳
%% GMT时间(格林尼治时间)比北京时间少8小时
get_today_zerotime_timestamp() ->
 calendar:datetime_to_gregorian_seconds({date(),{0,0,0}}) -  calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}}) - 8*60*60.

  

 

%%定时调度,从"mh_android"表中,统计这时刻的发送消息数-------send_trend--------------------------
total_message()->

        DbInfo = op_mongo:init_dbinfo(),
        {MongoConn, DbName, Collection}=op_mongo:split_mh_android(DbInfo),
         Zero_time = get_today_zerotime_timestamp(),        %获取mongo中0点时间戳
        {ok, Num} = mongo:do(unsafe, slave_ok, MongoConn, DbName, 
                                            fun() ->mongo:count( Collection, {"sut",  {<<"$gte">>,Zero_time}} ) end), %% 获取时间戳"sut"大于等于0点时间戳的总和                                    

  

mongo的时间类型,erlang中对其的处理

标签:androi   time   简单   time_t   second   end   blog   时间类   发送消息   

原文地址:http://www.cnblogs.com/unqiang/p/6028928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!