Thursday, February 21, 2019

Get date time in iphone

If we make a calendar app, we need to get phone date.
var com = NSDate()
This command return a String like this.
To use them, use split string like this.
let d = String(com)
let a = d.componentsSeparatedByString(" ")
let b = a[0].componentsSeparatedByString("-")
let year = b[0]
 let month = b[1]
 let day = b[2]

la.text = "Year: " + year + " month: " + month + " date: " + day

No comments:

Post a Comment