{"id":28707,"date":"2020-04-20T16:43:18","date_gmt":"2020-04-20T20:43:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28707"},"modified":"2020-04-22T16:58:36","modified_gmt":"2020-04-22T20:58:36","slug":"nsdateformatter-com","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/04\/20\/nsdateformatter-com\/","title":{"rendered":"NSDateFormatter.com"},"content":{"rendered":"<p><a href=\"https:\/\/nsdateformatter.com\">NSDateFormatter.com<\/a> is an interactive reference for date format strings and has some good tips (via <a href=\"https:\/\/twitter.com\/Freerunnering\/status\/1250948686114365442\">Kyle Howells<\/a>):<\/p>\n<blockquote cite=\"https:\/\/nsdateformatter.com\"><ul>\n<li>\nUse <code>dateStyle<\/code> and <code>timeStyle<\/code> over <code>dateFormat<\/code> whenever you can.\nExplain the date fallacies to your designer if you need to.\n<\/li>\n<li>\nIf you can&rsquo;t find a fitting <code>dateStyle\/timeStyle<\/code> to format your UI dates, then at least use\n<a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/dateformatter\/1417087-setlocalizeddateformatfromtempla\">\n  <code>dateFormatter.setLocalizedDateFormatFromTemplate(&#8230;)<\/code>\n<\/a> to account for the user&rsquo;s locale.\n<\/li>\n<li>When parsing ISO8601 internet dates, always use <code>ISO8601DateFormatter<\/code><\/li>\n<li>\nIf you can&rsquo;t because your API format doesn&rsquo;t fit ISO8601 and you still absolutely need to use a custom <code>dateFormat<\/code>,\nthen be sure to also set your <code>dateFormatter.locale<\/code> to the special value <code>Locale(identifier: \"en_US_POSIX\")<\/code>.\n<\/li>\n<\/ul><\/blockquote>\n<p>See also: <a href=\"http:\/\/goshdarnblocksyntax.com\">goshdarnblocksyntax.com<\/a>, <a href=\"https:\/\/goshdarnswiftui.com\">goshdarnswiftui.com<\/a>.<\/p>\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/10\/24\/wtf-auto-layout\/\">WTF Auto Layout?<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/11\/01\/swifts-if-case-let-syntax\/\">Swift&rsquo;s &ldquo;if case let&rdquo; Syntax<\/a><\/li>\n<\/ul>\n\n<p id=\"nsdateformatter-com-update-2020-04-22\">Update (2020-04-22): <a href=\"https:\/\/tyler.io\/rebecca-stand-and-the-phone-reason\/\">Tyler Hall<\/a>:<\/p>\n<blockquote cite=\"https:\/\/tyler.io\/rebecca-stand-and-the-phone-reason\/\">\n<p>Why wasn&rsquo;t it crashing for us in our testing?<\/p>\n<p>[&#8230;]<\/p>\n<p>Apple&rsquo;s documentation for that method says&#8230;<\/p><blockquote><p>Returns a date representation of a given string interpreted using the receiver&rsquo;s current settings.<\/p><\/blockquote><p>[&#8230;]<\/p><p>The customer dictated their bug report to us via email using Siri. They speak English, live outside Boston, but their phone&rsquo;s region was set to Uzbekistan instead of United States (or anything else more common).<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>NSDateFormatter.com is an interactive reference for date format strings and has some good tips (via Kyle Howells): Use dateStyle and timeStyle over dateFormat whenever you can. Explain the date fallacies to your designer if you need to. If you can&rsquo;t find a fitting dateStyle\/timeStyle to format your UI dates, then at least use dateFormatter.setLocalizedDateFormatFromTemplate(&#8230;) to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-04-20T20:43:21Z","apple_news_api_id":"c8b81faf-a2c5-443e-a913-84dd3b1bf75f","apple_news_api_modified_at":"2020-04-22T20:58:39Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/AyLgfr6LFRD6pE4TdOxv3Xw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[164,31,1667,30,1666,568,71,247,364],"class_list":["post-28707","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-documentation","tag-ios","tag-ios-13","tag-mac","tag-macos-10-15","tag-nsdateformatter","tag-programming","tag-siri","tag-time"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=28707"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28707\/revisions"}],"predecessor-version":[{"id":28775,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28707\/revisions\/28775"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}