How do I get the NSDateComponents of a single NSDate? I don't want the components of the difference between 2 dates, just the seconds, minutes, hours, day, month and year of a NSDate?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Converting (u)int64_t to NSNumbers
According to Apple Developer API Reference,
DateComponents
hassecond
,minute
,hour
,day
,month
,year
instance properties.The following Swift 4.2 / iOS 12 Playground code shows how to get seconds, minutes, hours, day, month and year components from a
Date
instance usingDateComponents
:in Swift 2.x the components you want are passed like this.
There's an example in the Apple docs, Listing 3: Getting a date’s components:
Note that you have to 'or' together the calendar units you want in the call of the
components
method.using NSCalendar's method:
- (NSDateComponents *)components:(NSUInteger)unitFlags fromDate:(NSDate *)date
like: