如何找到差异,比较并获取NSDate变量中的每个字段值? [英] How to find difference, compare and get each field values in NSDate variables?

查看:54
本文介绍了如何找到差异,比较并获取NSDate变量中的每个字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对NSDate变量执行以下操作?

How can i do the following operations on NSDate variables?

  1. 如何比较两个NSDate变量?

  1. How to compare two NSDate variables?

如何找到两个NSDate变量之间的差异?

How to find difference between two NSDate variables?

如何从NSDate变量中获取分钟,小时和天的每个单独值?

How to get each separate value of minute, hours and days from NSDate variable?

我们可以通过以下方式获取当前日期

We can get the current date by

NSDate *currentDate=[NSDate date]; 

但是它将给出以下结果yyyy-mm-dd hh:mm:ss GMT

But it will give the result of yyyy-mm-dd hh:mm:ss GMT

由此,我可以单独获得小时数吗?或仅月份值?

From this, can i get hour field alone? or month value only?

推荐答案

NSDate 类引用中,您可以使用实例方法来执行这些操作-

From NSDate class reference, you have instance methods to do these -

  1. 如何比较两个NSDate变量?回答: isEqualToDate:
  2. 如何找到两个NSDate变量之间的差异?回答: timeIntervalSinceDate:
  3. 如何从NSDate变量获取分钟,小时和天的每个单独值?链接

PS::最大程度地使用Google.

PS: Use Google to the maximum.

这篇关于如何找到差异,比较并获取NSDate变量中的每个字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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