Skip to content

Instantly share code, notes, and snippets.

@manchan
Created November 13, 2015 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manchan/3a8cb60694dc7ff84ef7 to your computer and use it in GitHub Desktop.
Save manchan/3a8cb60694dc7ff84ef7 to your computer and use it in GitHub Desktop.
RSSで取得したpubDateをNSDateFormatterで変換(Swift) ref: http://qiita.com/you_matz/items/ccbf337222b2cb98e65b
// string = "Wed, 04 Nov 2015 15:02:11 +0000"
let identifier = NSLocale.currentLocale().localeIdentifier
if identifier == "ja_JP" {
let dateFormatter = NSDateFormatter()
// 書式が変わらない固定ロケールで一度値を取得
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss ZZZZ"
let r_date = dateFormatter.dateFromString(string!)
if let d = r_date {
// ロケールを日本語にして曜日を取得
dateFormatter.locale = NSLocale(localeIdentifier: "ja_JP")
dateFormatter.dateFormat = "MM月dd日(E)"
tmpEntry.addObject(dateFormatter.stringFromDate(d))
}
}
// 日本語以外
else{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment