Search code examples
swiftnsdateformatter

How get time only prior 12:00 PM in Swift


let temp = dateFormatter.date(from: 2017-10-10 23:34:00)

how to identify if temp before 12:00 PM of after 12:00 PM


Solution

  • Try this....

    let temp1 = dateFormatter.date(from: 2017-10-10 23:34:00)
    
    dateFormatter.dateFormat = "a"
    dateFormatter.amSymbol = "AM"
    dateFormatter.pmSymbol = "PM"
    
    let temp2 = dateFormatter.string(from: temp1)
    
    if(temp2.contains("AM")){
         // your function
    }else{
         // your function
    }