<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emmer Inc &#187; DateTime</title>
	<atom:link href="http://blog.emmerinc.be/index.php/tag/datetime/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.emmerinc.be</link>
	<description>Tales from a .NET developer who's making the jump to the iPhone &#38; App Store wonderland.</description>
	<lastBuildDate>Mon, 06 Sep 2010 19:43:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Parsing serialized .NET DateTime to NSDate</title>
		<link>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 21:38:18 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[NSDate]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=22</guid>
		<description><![CDATA[In my application I have to parse a serialized .NET DateTime returned from a REST service to a NSDate object. I expected to be able to use the initWithString: constructor of the NSDate class, but this wasn&#8217;t the case. The initWithString: constructor expects a string with the following format &#8220;2009-02-25 22:00:00 +0100&#8243;, yet the serialized [...]]]></description>
			<content:encoded><![CDATA[<p>In my application I have to parse a serialized .NET DateTime returned from a REST service to a NSDate object. I expected to be able to use the initWithString: constructor of the NSDate class, but this wasn&#8217;t the case. The <a title="NSDate class reference" href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDate/initWithString:">initWithString:</a> constructor expects a string with the following format &#8220;2009-02-25 22:00:00 +0100&#8243;, yet the serialized .NET DateTime is in the following format &#8220;2009-02-25T22:00:00+01:00&#8243;. Notice the &#8220;T&#8221; and the semicolon in the timezone offset.</p>
<p>To solve this difference in format, one could manipulate the actual string to comply to the desired format or one could use the <a title="NSDateFormatter class reference" href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html">NSDateFormatter</a> class. The latter being the &#8220;cleanest&#8221; solution.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>formatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>formatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yyyy-MM-dd'T'HH:mm:ssZ&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>date <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>formatter dateFromString<span style="color: #002200;">:</span>text<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The used format patterns comply to the Unicode standard <a title="Unicode Technical Standard #35" href="http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns">UTS #35</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
