Created
March 14, 2015 21:04
-
-
Save eddieespinal/268ffa8475b92f3bb04a to your computer and use it in GitHub Desktop.
Get Time Of Day, e.g. Morning, Noon, Afternoon, Evening, Night, Late Night
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (NSString *)getTimeOfDay | |
| { | |
| // By: Eddie Espinal | |
| // morning 5AM-11:59AM | |
| // Noon 12PM-1PM | |
| // afternoon 1PM-5:59PM | |
| // evening 6PM-8:30PM | |
| // Night 8:30PM-11:59PM | |
| // Midnight 12AM | |
| // late night 12AM-4AM | |
| NSString *timeOfDay; | |
| NSDate *date = [[NSDate alloc] init]; | |
| NSUInteger hour = [date hour]; | |
| if (hour >= 5 && hour <= 11) | |
| { | |
| timeOfDay = NSLocalizedString(@"Morning", nil); | |
| } | |
| else if (hour > 11 && hour < 13) | |
| { | |
| timeOfDay = NSLocalizedString(@"Noon", nil); | |
| } | |
| else if (hour >= 13 && hour < 18) | |
| { | |
| timeOfDay = NSLocalizedString(@"Afternoon", nil); | |
| } | |
| else if (hour > 18 && hour <= 20) | |
| { | |
| timeOfDay = NSLocalizedString(@"Evening", nil); | |
| } | |
| else if (hour > 20 && hour < 24) | |
| { | |
| timeOfDay = NSLocalizedString(@"Night", nil); | |
| } | |
| else if (hour > 0 && hour <= 4) | |
| { | |
| timeOfDay = NSLocalizedString(@"Late Night", nil); | |
| } | |
| return timeOfDay; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment