2
2

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.

ISO8601形式の文字列をNSDateにする方法

Posted at

日時の情報をJSONなどでやりとりする時にこんな文字列をよく使う。

  • 2016-02-24T09:00:00.000Z
  • 2016-02-24T00:00:00.000+09:00

これらはISO8601という規格らしい。
サーバー側のTimezoneの設定次第ではどちらの形式で渡されてくるかわからない。なのでこれら両方に対応した NSDateFormatter のフォーマットがこちら

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ";

参考: http://stackoverflow.com/questions/16254575/how-do-i-get-iso-8601-date-in-ios

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?