How do I convert, NSDate
to NSString
so that only the year in @"yyyy" format is output to the string?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- “Zero out” sensitive String data in Swift
- back button text does not change
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
Define your own utility for format your date required date format for eg.
Hope to add more value by providing the normal formatter including the year, month and day with the time. You can use this formatter for more than just a year
Just add this extension:
If you don't have
NSDate
-descriptionWithCalendarFormat:timeZone:locale:
available (I don't believe iPhone/Cocoa Touch includes this) you may need to use strftime and monkey around with some C-style strings. You can get the UNIX timestamp from anNSDate
usingNSDate -timeIntervalSince1970
.