How can I convert this string "2021-06-14T19:07:41.183000" into an NSDate and keep only the year, month, day, hour? The T in the middle of it.
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
Format:
- year, month, day, as "XXXX-XX-XX"
- the letter "T" as a separator
- hour, minute, seconds, milliseconds, as "XX:XX:XX.XXX".
- the letter "Z" as a zone designator for zero offset, a.k.a. UTC, GMT, Zulu time.
The goal is a string that looks like this:
"2021-06-14T19:07:41.183000"
Create a var order_date return type as String? --
var order_date : String? { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" let date = dateFormatter.date(from: placedDate) dateFormatter.dateFormat = "dd MMM, yyyy" let dateString = dateFormatter.string(from: date!) return dateString }
And here is output--
14 Jun, 2021
Thanks for reading!!
Similar solutions you may also like...
- Create rounded bars in ios Charts || How to make Rounded Corner BarChart with iOS-charts?
- Why to use tuples when we can use an array or a set in Swift 5 Code Programming? | Arrays vs sets vs tuples
- Control Transfer Statements in iOS Programming Language Tutorial | What is the difference between continue, break, fall-through, throw and return in Swift Programming?
- Splash Screen | Custom Launch Screen in Swift | Launch Screen Animation in App (Swift 5.3) iOS Development
- How to Use Model-View-ViewModel (MVVM) in iOS | Architecture pattern in iOS | iOS design patterns Coding with Swift.
- When and Why are Swift optionals particularly confusing to beginners? | various ways to unwrap an optional in Swift Programming
- Swift Tutorials Difference between escaping and non escaping closures in swift 5.2 programming language with example
1 Comments
PokerStars | Bet with the best online casino players
ReplyDeleteBet with the best online casino players. Our world class PokerStars sportsbook 메리트 카지노 쿠폰 is your ticket to a world of Poker. 카지노사이트 Place 온카지노 bets on a huge range of