减去两个NSDate对象 [英] Subtracting two NSDate objects

查看:117
本文介绍了减去两个NSDate对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在iPhone中获得时差

我从JSON提要获取日期和时间。我需要找到从饲料中得到的日期和今天的日期和时间之间的差异。我有什么建议吗?

I´m getting date and time from a JSON feed. I need to find the difference between the date I´m getting from the feed and today´s date and time. Any suggestions how I can do this?

我知道我需要用从Feed中得到的日期减去当前日期,但我不知道该怎么做它。

I know I need to subtract the current date with the date I get from the feed, but I don´t know how to do it.

例如:

饲料日期:日期:2011-06- 10 15:00:00 +0000
今天:日期:2011-06-10 14:50:00 +0000

我需要显示差异是十分钟。

I need to display that the difference is ten minutes.

谢谢!

推荐答案

使用NSDate的 -dateWithString:从字符串创建两个NSDate对象,然后得到两个NSdate的区别对象使用

Create two NSDate objects from the strings using NSDate's -dateWithString:, then get the difference of the two NSdate objects using

NSTimeInterval diff = [date2 timeIntervalSinceDate:date1];

这篇关于减去两个NSDate对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆