Nick3150 Nick3150 - 1 year ago 89
Swift Question

How to get the specific date in iOS?

I'm working on a project where I have labels and images that change on a daily basis. My idea on how to go about this is I add assets for the images and have multiple files where I take the text (that contains the quote).

Two questions:

  1. Is there a better way of approaching this? (I'm fairly new to iOS, so I'm wondering if this is sound).

  2. How can I take the current day as in: May 22? (I just want to know how to get "22").

Answer Source

you need to use NSDate

let date = NSDate() // today
let dateStringFormatter = NSDateFormatter()
dateStringFormatter.dateFormat = "dd"
let d = dateStringFormatter.stringFromDate(date)
// d = "22"


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download