且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将24小时时间格式转换为12小时时间格式?

更新时间:2023-02-26 16:28:59

如你所说,你应该使用 NSDateFormatter 为你的期望的格式。希望这对你有帮助。

As you say, you should use NSDateFormatter for your desired format. Hope this will help you.

let date = NSDate()
let formatter = NSDateFormatter()
formatter.dateFormat = "hh:mm a"
let time = formatter.stringFromDate(date)

有关日期格式化程序的详细信息,请参阅 NSDateFormatter

For more information about date formatter see NSDateFormatter