ios - 环球银行金融电信协会 : Convert String from XLM to NSDate

标签 ios swift nsstring nsdate nsdateformatter

以下代码适用于模拟器,但不适用于设备。 我尝试用 xx 替换 Z,但没有成功。 任何帮助表示赞赏。

谢谢。

func convertDateStringToNSDate(dateString: String) -> NSDate {
        var dateFormatter = NSDateFormatter()
        // Sat, 20 Jun 2015 16:50:20 +0200

         dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss xx"
         let date: NSDate = dateFormatter.dateFromString(dateString)
         return date

    }

最佳答案

If you're working with fixed-format dates, you should first set the locale of the date formatter to something appropriate for your fixed format. In most cases the best locale to choose is en_US_POSIX, a locale that's specifically designed to yield US English results regardless of both user and system preferences. en_US_POSIX is also invariant in time (if the US, at some point in the future, changes the way it formats dates, en_US will change to reflect the new behavior, but en_US_POSIX will not), and between platforms (en_US_POSIX works the same on iPhone OS as it does on OS X, and as it does on other platforms).

// Setting the locale to POSIX ensures that
// the user's locale won't be used
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")

关于ios - 环球银行金融电信协会 : Convert String from XLM to NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30971813/

相关文章:

ios - 使用 swift 在 iOS 中访问联系人详细信息

ios - CATextLayer-如何禁用隐式动画?

html - 如何根据html标签在UILabel中显示html文本?

ios - 在 iPad 中以横向模式启动 iPhone App

ios - swift 静态库

ios - 使用NSUserDefaults的同步操作GCD队列导致的死锁

swift - 索引(: Int) method of Range in swift return incorrect value

ios - 矩形 UIButton

objective-c - 字符 * 与 NSString *

ios - 如何更改 UILabel 行中的垂直边距/间隙