How to find difference, compare and get each field values in NSDate variables?

浪子不回头ぞ 提交于 2019-12-11 14:24:33

问题


How can i do the following operations on NSDate variables?

  1. How to compare two NSDate variables?

  2. How to find difference between two NSDate variables?

  3. 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]; 

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?


回答1:


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

  1. How to compare two NSDate variables? Ans: isEqualToDate:
  2. How to find difference between two NSDate variables? Ans: timeIntervalSinceDate:
  3. How to get each separate value of minute, hours and days from NSDate variable? links

PS: Use Google to the maximum.



来源:https://stackoverflow.com/questions/4677618/how-to-find-difference-compare-and-get-each-field-values-in-nsdate-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!