Remember that in regions where daylight saving time is used, some watches may not exist on the days of the change of hours or they may occur twice. Both solutions below return Date? and use unboxing by force. You must handle a possible nil in your application.
Swift 3, 4, and iOS 8 / OS X 10.9 or later
let date = Calendar.current.date(bySettingHour: 9, minute: 30, second: 0, of: Date())!
Swift 2
Use NSDateComponents / DateComponents :
let gregorian = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! let now = NSDate() let components = gregorian.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: now)
Please note that if you call print(date) , the print time is in UTC. This is the same point in time, simply expressed in a different time zone from yours. Use NSDateFormatter to convert it to your local time.
Code different
source share