Skip to content

Instantly share code, notes, and snippets.

@snowshoes
Last active November 24, 2022 05:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snowshoes/1634c90d2a6b8bbafcdc3a46088dec26 to your computer and use it in GitHub Desktop.
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
// 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