Solved

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

Posted on 2011-09-19
7
520 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Information security is a multi-billion dollar industry. Just as lucrative is the black market industry which trades stolen identities, credit card numbers and software exploits all over the world. Nothing is hack-proof. The best one can do is make …
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now