Skip to content

Instantly share code, notes, and snippets.

@andrea-ale-sbarra
Created July 21, 2014 20:08
Show Gist options
  • Save andrea-ale-sbarra/21ed9c8fa8a4aa4ed8ad to your computer and use it in GitHub Desktop.
Save andrea-ale-sbarra/21ed9c8fa8a4aa4ed8ad to your computer and use it in GitHub Desktop.
Estendere la NSDate in swift e settaggi utili
extension NSDate
{
convenience
init(dateString:String) {
let dateStringFormatter = NSDateFormatter()
dateStringFormatter.dateFormat = "yyyy-MM-dd"
dateStringFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
let d = dateStringFormatter.dateFromString(dateString)
self.init(timeInterval:0, sinceDate:d)
}
}
Now you can create an NSDate from Swift just by doing:
NSDate(dateString:"2014-06-06")
@andrea-ale-sbarra
Copy link
Author

/*
x number
xx two digit number
xxx abbreviated name
xxxx full name

 a           AM/PM
 A           millisecond of day
 c           day of week (c,cc,ccc,cccc)
 d           day of month
 e           day of week (e,EEE,EEEE)
 F           week of month
 g           julian day (since 1/1/4713 BC)
 G           era designator (G=GGG,GGGG)
 h           hour (1-12, zero padded)
 H           hour (0-23, zero padded)
 L           month of year (L,LL,LLL,LLLL)
 m           minute of hour (0-59, zero padded)
 M           month of year (M,MM,MMM,MMMM)
 Q           quarter of year (Q,QQ,QQQ,QQQQ)
 s           seconds of minute (0-59, zero padded)
 S           fraction of second
 u           zero padded year
 v           general timezone (v=vvv,vvvv)
 w           week of year (0-53, zero padded)
 y           year (y,yy,yyyy)
 z           specific timezone (z=zzz,zzzz)
 Z           timezone offset +0000

 sql         y-M-d H:m:s
 rss         [E, ]d MMM y[y] H:m:s Z|z[zzz]
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment