Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-19
7
Medium Priority
?
550 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 750 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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