I want to convert "2014-07-15 06:55:14.198000+00:00" this string date to NSDate in Swift.
相关问题
- how to split a list into a given number of sub-lis
- 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?
- JSP String formatting Truncate
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Selecting only the first few characters in a strin
- Enum with associated value conforming to CaseItera
try this:
For further query, check NSDateFormatter and DateFormatter classes of Foundation framework for Objective-C and Swift, respectively.
Swift 3 and later (Swift 4 included)
To add String within Date Format in Swift, I did this
Details
Swift 4, xCode 9.2 / Swift 3, xCode 8.2.1
Date format extensions
Usage
Result
More information
About date format
The code fragments on this QA page are "upside down"...
The first thing Apple mentions is that you cache your formatter...
Link to Apple doco stating exactly how to do this:
Use a global...
Then simply use that formatter anywhere...
or
Or use any of the other many, many convenient methods on DateFormatter.
It is that simple.
(If you write an extension on String, your code is completely "upside down" - you can't use any dateFormatter calls!)
Note that usually you will have a few of those globals .. such as "formatForClient" "formatForPubNub" "formatForDisplayOnInvoiceScreen" .. etc.
Since Swift 3, many of the NS prefixes have been dropped.
Below are some string to date format converting options can be usedin swift iOS.
Thursday, Dec 27, 2018
format=EEEE, MMM d, yyyy
12/27/2018
format=MM/dd/yyyy
12-27-2018 09:59
format=MM-dd-yyyy HH:mm
Dec 27, 9:59 AM
format=MMM d, h:mm a
December 2018
format=MMMM yyyy
Dec 27, 2018
format=MMM d, yyyy
Thu, 27 Dec 2018 09:59:19 +0000
format=E, d MMM yyyy HH:mm:ss Z
2018-12-27T09:59:19+0000
format=yyyy-MM-dd'T'HH:mm:ssZ
27.12.18
format=dd.MM.yy
09:59:19.815
format=HH:mm:ss.SSS