Last active
November 24, 2022 05:04
-
-
Save snowshoes/1634c90d2a6b8bbafcdc3a46088dec26 to your computer and use it in GitHub Desktop.
[Format time of the day Swift]find a way to get time of the day in words #tags: swift, date, time
This file contains 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
// http://stackoverflow.com/questions/32649039/formatting-time-of-the-day-swift-morning-afternoon-evening-any-time | |
// Same Principle as BigNerdRanch Silver Challenge | |
let hour = Calendar.currentCalendar().component(.Hour, fromDate: Date()) | |
switch hour { | |
case 6..<12 : print(NSLocalizedString("Morning", comment: "Morning")) | |
case 12 : print(NSLocalizedString("Noon", comment: "Noon")) | |
case 13..<17 : print(NSLocalizedString("Afternoon", comment: "Afternoon")) | |
case 17..<22 : print(NSLocalizedString("Evening", comment: "Evening")) | |
default: print(NSLocalizedString("Night", comment: "Night")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment