从字符串转换日期

时间:2018-10-14 07:08:14

标签: ios swift xcode

am从api ..获取日期和时间,并进行如下转换:

   let inputDateAsString = match.dateGregorian!
   let formatter = DateFormatter()
   formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
   if let date = formatter.date(from: inputDateAsString) {
     if MOLHLanguage.isArabic(){
        formatter.locale = NSLocale(localeIdentifier: "eng") as Locale?
     }else{
        formatter.locale = NSLocale(localeIdentifier: "eng") as Locale?
      }
     formatter.dateFormat = "hh:mm a"
     let outputDate = formatter.string(from: date)
     time = outputDate
     time = time.replacingOccurrences(of: "PM", with: "م")

      }else {
  print("There was an error decoding the string")
 }

这在大多数设备上都可以正常工作……只是在一个设备上将不起作用,也不会输入此参数并返回null ..为什么?

它将始终返回此值在此一台设备中解码字符串时出错...

以及如何解决这个问题?

0 个答案:

没有答案
相关问题