How do I get the day of the week as a string?
相关问题
- CALayer - backgroundColor flipped?
- 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
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Many of the answers here are deprecated. This works as of iOS 8.4 and gives you the day of the week as a string and as a number.
Just use these three lines:
I think this topic is really useful, so I post some code Swift 2.1 compatible.
Anywhere you can call:
Swift 3.0
As @delta2flat suggested, I update answer giving user the ability to specify custom format.
Swift 2: Get day of week in one line. (based on neoscribe answer)
there are three symbols we can use to format day of week:
The following two documents may help you.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
Demo:
you can test your pattern on this website:
http://nsdateformatter.com/