Converting date and time to a string in Swift
Forums:
let now = NSDate()
let shortStyle = NSDateFormatter.localizedStringFromDate(now,
dateStyle: NSDateFormatterStyle.ShortStyle,
timeStyle: NSDateFormatterStyle.ShortStyle)
//shortStyle is "6/22/15, 4:10 PM"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let customStyle = dateFormatter.stringFromDate(now)
//customStyle is "2015-06-22"
- Log in to post comments