开发者

Fetching time related data which includes current time

开发者 https://www.devze.com 2023-03-08 21:23 出处:网络
I have dat开发者_Python百科a stored where one of the entity\'s attributes is startTime which is stores as an NSNumber (NSTimeInterval) and another attribute with the item\'s duration.

I have dat开发者_Python百科a stored where one of the entity's attributes is startTime which is stores as an NSNumber (NSTimeInterval) and another attribute with the item's duration.

How would I go about fetching the single item which is valid for "now" - i.e. teh item who's start time + duration includes the current time ([NSDate date])?


Have a look at this SO question: NSPredicate syntax for DATEADD?


You need to use an NSDateFormatter to grab the current time/date and then use NSDateComponents to break this into hours/mins/seconds (as required).

Then increment your startTime and duration onto it.

Then use the components to create a new NSDate which will be your result.

0

精彩评论

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