2015-11-07 69 views
0

我试图在我的应用程序上从不同用户的帖子出现的新闻源。解析创建比较当前时间在几分钟内

我试图在Feed项目上显示的是一个时间戳,表示当前时间和创建该帖子的时间之间的差异。

我一直在试图对其进行测试,但我在logcat中得到的是超过40万

这是我的代码值:

DateFormat originalFormat = new SimpleDateFormat("EEE MMM DDD HH:mm:ss z yyyy"); 
       try { 
        Log.i("Parse time: " , String.valueOf(posts.getCreatedAt())); 
        Date originaldate = originalFormat.parse(posts.getCreatedAt().toString()); 
        long timeMilliseconds = originaldate.getTime(); 
        Log.i("Server time (s): ", String.valueOf(TimeUnit.MILLISECONDS.toSeconds(timeMilliseconds))); 
        long timeMinutes = TimeUnit.MILLISECONDS.toMinutes(timeMilliseconds); 
        Log.i("Server time (min): ", String.valueOf(timeMinutes)); 
        Calendar calendar = Calendar.getInstance(); 
        long seconds = TimeUnit.MILLISECONDS.toSeconds(calendar.getTimeInMillis()); 
        Log.i("Current time (s): ", String.valueOf(seconds)); 
        long minutes = TimeUnit.SECONDS.toMinutes(seconds); 
        Log.i("Current time (min): ", String.valueOf(minutes)); 
        long differenceMinutes = minutes - timeMinutes; 
        Log.i("Difference time (min):", String.valueOf(differenceMinutes)); 

       } 
       catch (java.text.ParseException e){ 
        e.printStackTrace(); 
       } 

编辑

这是我的logcat:

11-07 09:20:29.820 19390-19430/? I/Server time (s):: 1420617846 
11-07 09:20:29.820 19390-19430/? I/Server time (min):: 23676964 
11-07 09:20:29.820 19390-19430/? I/Current time (s):: 1446884429 
11-07 09:20:29.820 19390-19430/? I/Current time (min):: 24114740 
11-07 09:20:29.820 19390-19430/? I/Difference time (min):: 437776 
+0

可能的重复[如何计算两个时间字段之间的时间差,相对于日期更改](http://stackoverflow.com/questions/5172593/how-to-calculate-the-time-两个时间字段之间的差异与尊重t) – Shivam

回答

相关问题