Solved

how to check if the time within the specific range using xcode for iphone

Posted on 2011-09-19
7
547 Views
Last Modified: 2012-05-12
how i can check if the time is with in the  specific range using xcode for example if i have time = 4:00PM

i need         if condition if(time is between 1:00 PM and 5:00 PM)
                           {
                                   true
                            }
                  else
                            {
                                  false
                            }


best regards
0
Comment
Question by:deniro1974
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:SpeedyApocalypse
ID: 36564331
Is 4:00PM stored as a string, NSDate object, etc?
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 250 total points
ID: 36564731
If the time is in hours, so compare three integer values like:
if (x >= a && x <= b)
{
}
If you are talking about NSDate objects, you can use NSCalendar and NSDateComponents to get the hours from the NSDate objects.
You can compare three NSDate objects and this is probably the simplest way:
if (([theDate compare:fromDate] != NSOrderedAscending) && ([theDate compare:toDate] != NSOrderedDescending))
{
  // do something
}


0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 36564745
Take a look also here - timeIntervalSinceReferenceDate:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html
You can convert the NSDate objects to NSTimeInterval and compare them as three float values.
0
 

Author Comment

by:deniro1974
ID: 36564994
dear speedy,

i want it to be NSdate.

Best regards
0
 

Author Closing Comment

by:deniro1974
ID: 36572121
it's not the solution i need but it was helpful
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A common question or need, when setting-up a new Mac for someone would be to make all of the applications, installed, available from the dock. Many people often do not realize an application is installed unless it is in the dock. Creating a custo…
CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question