swift get day from available string
let dateString = "2018-12-24 18:00:00 UTC"
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss 'UTC'"
guard let date = formatter.date(from: dateString) else {
return
}
formatter.dateFormat = "yyyy"
let year = formatter.string(from: date)
formatter.dateFormat = "MM"
let month = formatter.string(from: date)
formatter.dateFormat = "dd"
let day = formatter.string(from: date)
print(year, month, day) // 2018 12 24
Also in Swift:
- swift remove tableview cell
- swift set uicolor
- swiftui font color
- swift dispatch after
- how to set the center in view in swift
- swift list
- swift uitableview insert cell
- print things in swift
- store bool value in nsuserdefaults swift
- xcode how to get aspect ratio of device
- swift image button blue
- use alamofire to login in swift 5
- xcode how to know which textfield is selected
- how to show notification icon on tabbar item swift
- swift how to make a variable
- swift check if regex is in string
- swift declare optional values
- swift uitextfield only numbers keyboard lock programmatically
- remove child from firebase swift
- Library not loaded: @rpath/App.framework/App
- dart capitalize first letter of each word
- set image width and height swiftui
- xcode cannot find uiimagepickercontrolleroriginalimage in scope
- swift change enum value