What am I doing wrong with allowsFractionalUnits on NSDateComponentsFormatter?

前端 未结 3 1559
孤独总比滥情好
孤独总比滥情好 2020-12-28 13:30

Basically what I want is to get the value of a time interval represented in hours only, without rounding it to full hours (using NSDateComponentsFormatter to get it properly

3条回答
  •  -上瘾入骨i
    2020-12-28 13:42

    enter code hereAs far as i understood , You want to display time in 12-Hour formate Right ? Below is the code : Swift->

    let dateAsString = "20:30"
    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "HH:mm"
    let date = dateFormatter.dateFromString(dateAsString)
    
    dateFormatter.dateFormat = "h:mm a"
    let date12 = dateFormatter.stringFromDate(date!)
    txtText.text = date12 
    

提交回复
热议问题