how can I retrieve the date and time from a NSDate. I want to see them separately. thanks
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- 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
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
In Swift you can enjoy yourself with extension, for instance:
And then, anywhere in your code you can do:
i would go with using NSDateComponents and NSCalendar if you really want to have the values for the minute, hour and the date ... Something like this:
then you can use the properties of the components to access the value of each components with component.hour, component.year, etc.
Also please note that if you are going with the NSDateFormatter example - then you should remember that NSDateFormatter is a heavy object and you should really reuse it if possible ...
There are many many different ways to represent the date and time so check NSDateFormatter for more info.
I'd use the following over the other answers:
The advantage it has is that it will set the formatting to what the user has set in their system settings. That way you don't have to worry about items like if the user prefers their short dates in the format 10/31/11 or 31/10/11. See the documentation for a list of styles that are available.
Swift 2.2: