How do I get the current Date in short format in Swift

Xcode 11 or later • Swift 5.1 or later extension TimeZone { static let gmt = TimeZone(secondsFromGMT: 0)! } extension Locale { static let ptBR = Locale(identifier: “pt_BR”) } extension Formatter { static let date = DateFormatter() } extension Date { func localizedDescription(date dateStyle: DateFormatter.Style = .medium, time timeStyle: DateFormatter.Style = .medium, in timeZone: TimeZone … Read more

How to convert a date string with optional fractional seconds using Codable in Swift?

You can use two different date formatters (with and without fraction seconds) and create a custom DateDecodingStrategy. In case of failure when parsing the date returned by the API you can throw a DecodingError as suggested by @PauloMattos in comments: iOS 9, macOS 10.9, tvOS 9, watchOS 2, Xcode 9 or later The custom ISO8601 … Read more

Show AM/PM in capitals in swift

You can set your DateFormatter amSymbol and pmSymbol as follow: Xcode 8.3 • Swift 3.1 let formatter = DateFormatter() formatter.locale = Locale(identifier: “en_US_POSIX”) formatter.dateFormat = “h:mm a ‘on’ MMMM dd, yyyy” formatter.amSymbol = “AM” formatter.pmSymbol = “PM” let dateString = formatter.string(from: Date()) print(dateString) // “4:44 PM on June 23, 2016\n”

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)