I am working on an app that needs to find someones age depending on their birthday. I have a simple NSDate
but how would I find this with NSDateFormatter
?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
NSYearCalendarUnit is deprecated. It is replaced by NSCalendarUnitYear
NSDateFormatter
is for formatting dates (duh!). As a rule of thumb, whenever you need to perform some computation on anNSDate
you use aNSCalendar
and associated classes, such asNSDateComponents
.Check this, I used "(NSDateComponents *)components:(NSCalendarUnit)unitFlags fromDate:(NSDate *)startingDate toDate:(NSDate *)resultDate options:(NSCalendarOptions)opts" and added localization
I found a shorter way to do what you were trying to accomplish if you just want to know how old someone is.