1
1

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.

日付をjson形式で送ってxcodeで日本語形式に表示例「ISO8601形式(iOS10.0以上)」

Posted at

Json形式

date('Y-m-d',mktime(0, 0, 0, $month, $i, $year))."T00:00:00+00:00"

xcode文

                        let datew = json["calendar"][i]["date"].string
                        print("datew")
                        print(datew)
                        
                        let datewx = datew!
                        // iOS10.0以上ならズバリのフォーマッターが使える
                        let iso8601DateFormatter = ISO8601DateFormatter()
                        // 変換
                        let date = iso8601DateFormatter.date(from: datewx) // 拡張形式
                        
                        
                        print("datew日付変換")
                        print(date)
                        
                        
                        let dateFormatter = DateFormatter()
                        // フォーマット設定
                        dateFormatter.dateFormat = "yyyy'年'M'月'd'日" // 曜日1文字
                        //dateFormatter.dateFormat = "M'月'd'日 ('EEEE')'" // 曜日3文字
                        
                        // ロケール設定(日本語・日本国固定)
                        dateFormatter.locale = Locale(identifier: "ja_JP")
                        
                        // タイムゾーン設定(日本標準時固定)
                        dateFormatter.timeZone = TimeZone(identifier: "Asia/Tokyo")
                        
                        // 変換
                        let str = dateFormatter.string(from: date!)
                        
                        print("datew変換後")
                        // 結果表示
                        print(str) 
                
                
                    }

参考リンク先
String ⇒ Date 変換のISO8601形式(iOS10.0以上)を参考
https://www.2nd-walker.com/2020/01/14/swift-date-string-convert/

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?