开发者

Set one date from another date

I am using Objective-C within X-code.

I am iterating through a dictionary which contains a date value as one of it's keys. All I want to do is get an array of all the distinct dates so I can use them in a table, as headers. I just plan on iterating the dictionary and adding dates to a mutable array each time I encounter a new date.

I must set previous date to new date for comparisons to work a开发者_如何转开发nd I am having a very difficult time figuring out how to set one date equal to another date.

This seems like it should be such a simple thing to do and I am trying to avoid converting the dates to strings first - but if that's what I have to do, then so be it.

Any help would be appreciated. Thanks, Gerry O.


If you know the time offset is same as GMT, you could do it by dividing the date's timestamp by 86400 seconds (or three more 0s in milliseconds) and comparing those. If a time offset is there, add or subtract by 3600 seconds per hour before you divide them. But then again, leap years and seconds would break that...

Most languages have libraries support extracting the year, date, month, etc. They take everything into account, usually.

In Objc, you can get a NSDateComponents from NSCalendar's components:fromDate: method. After this, you can call the components to see exactly what each component (I suggest year, month, day) is.


I think you want code to compare dates and You need two loops nested.... where in outer loops iterates with conditional inner loop... In inner loop you just check that previously you had the same date or not...

please go through the below post on same site...

How to compare two dates in Objective-C

hope you will get solution... else clarify your question....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜