Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Even though Mac OS X has been around for many years now, certain well-liked and eminently useful software apps never made the jump from Mac OS 9 to Mac OS X. Ever used Word Perfect for Mac? Version 3.5 was the last version, built for Mac OS 9. Who c…
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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