Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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