4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swiftで文字列の日付フォーマットを別フォーマットに置き換える

Last updated at Posted at 2015-07-07

swiftで、文字列の日付を変更する際によく分からなくなるので備忘録として。

Swift

let d = "Mon Jul 01 00:00:00 +0000 2015"
let formatter = NSDateFormatter()
formatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
if let date = formatter.dateFromString(d) {
    formatter.dateFormat = "yyyy-MM-dd"
    let dateString = formatter.stringFromDate(date)
    print(dateString)   // "2015-07-01"
}

フォーマットは、こちらのサイトが良く載っています。いまいち、分かりやすくはないですが。。
http://waracle.net/iphone-nsdateformatter-date-formatting-table/

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?