<?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>OdedCoster.com/blog &#187; Oded Coster</title>
	<atom:link href="http://OdedCoster.com/blog/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://OdedCoster.com/blog</link>
	<description>One day I will think of something clever to put here</description>
	<lastBuildDate>Wed, 06 Feb 2013 22:30:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Did you know? A .NET CSV parser that comes with Visual Studio?</title>
		<link>http://OdedCoster.com/blog/2012/03/28/did-you-know-a-net-csv-parser-that-comes-with-visual-studio/</link>
		<comments>http://OdedCoster.com/blog/2012/03/28/did-you-know-a-net-csv-parser-that-comes-with-visual-studio/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 19:28:34 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=179</guid>
		<description><![CDATA[In the Microsoft.VisualBasic.FileIO (Microsoft.VisualBasic.dll) namespace lives the TextFieldParser class. This useful little class can be used to parse structured text files &#8211; either delimited or fixed length. You can iterate over the lines in the file and extract the data through the ReadFields method. Since it is provided by Microsoft, you can use it in [...]]]></description>
				<content:encoded><![CDATA[<p>In the <code><a href="http://msdn.microsoft.com/en-us/library/ms127948.aspx" title="Microsoft.VisualBasic.dll" target="_blank">Microsoft.VisualBasic.FileIO</a></code> (Microsoft.VisualBasic.dll) namespace lives the <code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx" title="TextFieldParser" target="_blank">TextFieldParser</a></code> class.</p>
<p>This useful little class can be used to parse structured text files &#8211; either delimited or fixed length. You can iterate over the lines in the file and extract the data through the <code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.readfields.aspx" title="ReadFields" target="_blank">ReadFields</a></code> method.</p>
<p>Since it is provided by Microsoft, you can use it in environments that do not allow &#8220;third-party&#8221; libraries and as it is a .NET libarary you can use it in any .NET language (yes, C# and F# included) &#8211; just import the library.</p>
<p>The examples on MSDN are all in VB.NET, but are easily translated to other .NET dialects.</p>
<p>- <a href="http://msdn.microsoft.com/en-us/library/cakac7e6.aspx" title="How to: Read From Comma-Delimited Text Files" target="_blank">How to: Read From Comma-Delimited Text Files</a><br />
- <a href="http://msdn.microsoft.com/en-us/library/zezabash.aspx" title="How to: Read From Fixed-width Text Files" target="_blank">How to: Read From Fixed-width Text Files</a><br />
- <a href="http://msdn.microsoft.com/en-us/library/w30ffays.aspx" title="How to: Read From Text Files with Multiple Formats" target="_blank">How to: Read From Text Files with Multiple Formats</a></p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2012/03/28/did-you-know-a-net-csv-parser-that-comes-with-visual-studio/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Class libraries do not have configuration</title>
		<link>http://OdedCoster.com/blog/2012/03/19/class-libraries-do-not-have-configuration/</link>
		<comments>http://OdedCoster.com/blog/2012/03/19/class-libraries-do-not-have-configuration/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 19:42:05 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET c# programming]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=124</guid>
		<description><![CDATA[Why is that? If one takes the time to think about it, class libraries only ever execute in the context of an application &#8211; a web application, a console application, a unit test runner or some other executable. A class library gets loaded into the memory space of the application and gets called and executed [...]]]></description>
				<content:encoded><![CDATA[<p>Why is that?</p>
<p>If one takes the time to think about it, class libraries only ever execute in the context of an application &#8211; a web application, a console application, a unit test runner or some other executable.</p>
<p>A class library gets loaded into the memory space of the application and gets called and executed there.</p>
<p>It makes sense then that the executing application should be the one deciding on how to configure a class library it is using, rather than the other way around.</p>
<p>The .NET framework configuration subsystem subscribes to this idea &#8211; when using the <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx" title="System.Configuration Namespace on MSDN" target="_blank"><code>System.Configuration</code> namespace</a>, the application configuration file will be the one queried, even if there is a configuration file matching the dll name.</p>
<p>I would add that configuration should be treated as a dependency &#8211; the values should be injected into any class or method that required them &#8211; read the excellent blog by Paul Hiles &#8211; <a href="http://www.devtrends.co.uk/blog/configuration-settings-are-a-dependency-that-should-be-injected" title="Configuration Settings Are A Dependency That Should Be Injected" target="_blank">Configuration Settings Are A Dependency That Should Be Injected</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2012/03/19/class-libraries-do-not-have-configuration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Date and Time format strings in .NET &#8211; Understanding format strings</title>
		<link>http://OdedCoster.com/blog/2011/12/13/date-and-time-format-strings-in-net-understanding-format-strings/</link>
		<comments>http://OdedCoster.com/blog/2011/12/13/date-and-time-format-strings-in-net-understanding-format-strings/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 22:20:43 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[Formatting]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=131</guid>
		<description><![CDATA[Date and Time format strings come in two flavors &#8211; standard and custom. Whenever these are used, the CultureInfo that is used with them comes into play. If an IFormatProvider is not specified, the CultureInfo assigned to the current thread is used. Standard format strings These are all single character format specifiers &#8211; they each [...]]]></description>
				<content:encoded><![CDATA[<p>Date and Time format strings come in two flavors &#8211; <a title="Standard Date and Time format strings" href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx" target="_blank">standard</a> and <a title="Custom Date and Time format strings" href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx" target="_blank">custom</a>. </p>
<p>Whenever these are used, the <code>CultureInfo</code> that is used with them comes into play. If an <code>IFormatProvider</code> is not specified, the <code>CultureInfo</code> assigned to the current thread is used.</p>
<h2>Standard format strings</h2>
<p>These are all single character format specifiers &#8211; they each can be thought of as representing longer, culture sensitive custom format strings.</p>
<p>Any format string that contains more than one character (including white space) is considered to be a custom format specifier.</p>
<p>A <code>FormatException</code> will be thrown if the format specifier is not one of the known ones (listed in the table below):</p>
<table>
<tbody>
<tr>
<th>Format specifier</th>
<th>Description</th>
</tr>
<tr>
<td>&#8220;d&#8221;</td>
<td>Short date pattern</td>
</tr>
<tr>
<td>&#8220;D&#8221;</td>
<td>Long date pattern</td>
</tr>
<tr>
<td>&#8220;f&#8221;</td>
<td>Full date/time pattern (short time)</td>
</tr>
<tr>
<td>&#8220;F&#8221;</td>
<td>Full date/time pattern (long time)</td>
</tr>
<tr>
<td>&#8220;g&#8221;</td>
<td>General date/time pattern (short time)</td>
</tr>
<tr>
<td>&#8220;G&#8221;</td>
<td>General date/time pattern (long time)</td>
</tr>
<tr>
<td>&#8220;M&#8221;, &#8220;m&#8221;</td>
<td>Month/day pattern</td>
</tr>
<tr>
<td>&#8220;O&#8221;, &#8220;o&#8221;</td>
<td>Round-trip date/time pattern</td>
</tr>
<tr>
<td>&#8220;R&#8221;, &#8220;r&#8221;</td>
<td>RFC1123 pattern</td>
</tr>
<tr>
<td>&#8220;s&#8221;</td>
<td>Sortable date/time pattern</td>
</tr>
<tr>
<td>&#8220;t&#8221;</td>
<td>Short time pattern</td>
</tr>
<tr>
<td>&#8220;T&#8221;</td>
<td>Long time pattern</td>
</tr>
<tr>
<td>&#8220;u&#8221;</td>
<td>Universal sortable date/time pattern</td>
</tr>
<tr>
<td>&#8220;U&#8221;</td>
<td>Universal full date/time pattern</td>
</tr>
<tr>
<td>&#8220;Y&#8221;, &#8220;y&#8221;</td>
<td>Year month pattern</td>
</tr>
</tbody>
</table>
<p>Take a look at the <a href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx" title="Standard Date and Time format strings" target="_blank">documentation</a> for more detail.</p>
<p>Standard format strings are simple to use &#8211; when formatting a <code>DateTime</code> as a <code>string</code> or parsing a <code>string</code> into a <code>DateTime</code> (using <code>ParseExact</code> or <code>TryParseExact</code>).</p>
<p>Formatting examples:</p>
<pre>
DateTime.Now.ToString("f");
// 13 December 2011 19:35

DateTime.Now.ToString("f", CultureInfo.GetCultureInfo("he-IL"));
// יום שלישי 13 דצמבר 2011 19:35

DateTime.Now.ToString("D");
// 13 December 2011

DateTime.Now.ToString("D", CultureInfo.GetCultureInfo("ru-RU"));
// 13 декабря 2011 г.
</pre>
<p>Parsing examples (really just the opposite of the above):</p>
<pre>
DateTime.ParseExact("13 December 2011 19:35", "f", 
                    CultureInfo.GetCultureInfo("en-GB"))

DateTime.ParseExact("יום שלישי 13 דצמבר 2011 19:35", "f", 
                    CultureInfo.GetCultureInfo("he-IL"))

DateTime.ParseExact("13 December 2011", "D", 
                    CultureInfo.GetCultureInfo("en-GB"))

DateTime.ParseExact("13 декабря 2011 г.", "D", 
                    CultureInfo.GetCultureInfo("ru-RU"));
</pre>
<h2>Custom format strings</h2>
<p>Any string that contains more than one character will be considered to be a custom format string. </p>
<p>Custom format strings allow you to exactly match and parse any string representing a date and to convert a <code>DateTime</code> to any custom date string for display. They provide the most flexibility in parsing and outputting but are more complex to understand, construct and use than standard format strings.</p>
<p>All characters are allowed in the format string and each would be interpreted unchanged, unless it is one of the following format specifiers:</p>
<table>
<tr>
<th>Format specifier</th>
<th>Description</th>
</tr>
<tr>
<td>&#8220;d&#8221;</td>
<td>The day of the month, from 1 through 31</td>
</tr>
<tr>
<td>&#8220;dd&#8221;</td>
<td>The day of the month, from 01 through 31</td>
</tr>
<tr>
<td>&#8220;ddd&#8221;</td>
<td>The abbreviated name of the day of the week</td>
</tr>
<tr>
<td>&#8220;dddd&#8221;</td>
<td>The full name of the day of the week</td>
</tr>
<tr>
<td>&#8220;f&#8221;</td>
<td>The tenths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;ff&#8221;</td>
<td>The hundredths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;fff&#8221;</td>
<td>The milliseconds in a date and time value</td>
</tr>
<tr>
<td>&#8220;ffff&#8221;</td>
<td>The ten thousandths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;fffff&#8221;</td>
<td>The hundred thousandths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;ffffff&#8221;</td>
<td>The millionths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;fffffff&#8221;</td>
<td>The ten millionths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;F&#8221;</td>
<td>If non-zero, the tenths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;FF&#8221;</td>
<td>If non-zero, the hundredths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;FFF&#8221;</td>
<td>If non-zero, the milliseconds in a date and time value</td>
</tr>
<tr>
<td>&#8220;FFFF&#8221;</td>
<td>If non-zero, the ten thousandths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;FFFFF&#8221;</td>
<td>If non-zero, the hundred thousandths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;FFFFFF&#8221;</td>
<td>If non-zero, the millionths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;FFFFFFF&#8221;</td>
<td>If non-zero, the ten millionths of a second in a date and time value</td>
</tr>
<tr>
<td>&#8220;g&#8221;, &#8220;gg&#8221;</td>
<td>The period or era</td>
</tr>
<tr>
<td>&#8220;h&#8221;</td>
<td>The hour, using a 12-hour clock from 1 to 12</td>
</tr>
<tr>
<td>&#8220;hh&#8221;</td>
<td>The hour, using a 12-hour clock from 01 to 12</td>
</tr>
<tr>
<td>&#8220;H&#8221;</td>
<td>The hour, using a 24-hour clock from 0 to 23</td>
</tr>
<tr>
<td>&#8220;HH&#8221;</td>
<td>The hour, using a 24-hour clock from 00 to 23</td>
</tr>
<tr>
<td>&#8220;K&#8221;</td>
<td>Time zone information</td>
</tr>
<tr>
<td>&#8220;m&#8221;</td>
<td>The minute, from 0 through 59</td>
</tr>
<tr>
<td>&#8220;mm&#8221;</td>
<td>The minute, from 00 through 59</td>
</tr>
<tr>
<td>&#8220;M&#8221;</td>
<td>The month, from 1 through 12</td>
</tr>
<tr>
<td>&#8220;MM&#8221;</td>
<td>The month, from 01 through 12</td>
</tr>
<tr>
<td>&#8220;MMM&#8221;</td>
<td>The abbreviated name of the month</td>
</tr>
<tr>
<td>&#8220;MMMM&#8221;</td>
<td>The full name of the month</td>
</tr>
<tr>
<td>&#8220;s&#8221;</td>
<td>The second, from 0 through 59</td>
</tr>
<tr>
<td>&#8220;ss&#8221;</td>
<td>The second, from 00 through 59</td>
</tr>
<tr>
<td>&#8220;t&#8221;</td>
<td>The first character of the AM/PM designator</td>
</tr>
<tr>
<td>&#8220;tt&#8221;</td>
<td>The AM/PM designator</td>
</tr>
<tr>
<td>&#8220;y&#8221;</td>
<td>The year, from 0 to 99</td>
</tr>
<tr>
<td>&#8220;yy&#8221;</td>
<td>The year, from 00 to 99</td>
</tr>
<tr>
<td>&#8220;yyy&#8221;</td>
<td>The year, with a minimum of three digits</td>
</tr>
<tr>
<td>&#8220;yyyy&#8221;</td>
<td>The year as a four-digit number</td>
</tr>
<tr>
<td>&#8220;yyyyy&#8221;</td>
<td>The year as a five-digit number</td>
</tr>
<tr>
<td>&#8220;z&#8221;</td>
<td>Hours offset from UTC, with no leading zeros</td>
</tr>
<tr>
<td>&#8220;zz&#8221;</td>
<td>Hours offset from UTC, with a leading zero for a single-digit value</td>
</tr>
<tr>
<td>&#8220;zzz&#8221;</td>
<td>Hours and minutes offset from UTC</td>
</tr>
<tr>
<td>&#8220;:&#8221;</td>
<td>The time separator</td>
</tr>
<tr>
<td>&#8220;/&#8221;</td>
<td>The date separator</td>
</tr>
<tr>
<td>&#8220;string&#8221;, &#8216;string&#8217;</td>
<td>Literal string delimiter</td>
</tr>
<tr>
<td>%</td>
<td>Defines the following character as a custom format specifier</td>
</tr>
<tr>
<td>\</td>
<td>The escape character</td>
</tr>
<tr>
<td>Any other character</td>
<td>The character is copied to the result string unchanged</td>
</tr>
</table>
<p>Several of these merit special discussion:</p>
<h3>&#8220;:&#8221; &#8211; the time separator</h3>
<p>When &#8220;:&#8221; appears in a custom format string, is gets replaced with the time separator defined in the <code>CultureInfo</code> being used. For example, in the &#8220;it-IT&#8221; culture, the time separator is a &#8220;.&#8221;.</p>
<h3>&#8220;/&#8221; &#8211; the date separator</h3>
<p>When &#8220;/&#8221; appears in a custom format string, is gets replaced with the date separator defined in the <code>CultureInfo</code> being used. For example, in the &#8220;ar-DZ&#8221; culture, the date separator is a &#8220;-&#8221;.</p>
<h3>&#8220;string&#8221;, &#8216;string&#8217; &#8211; the literal string delimiter</h3>
<p>You can use single and double quotes as literal string delimiters within a format string &#8211; any such delimited string within a format string would appear verbatim in the string being parsed or output.</p>
<h3>&#8220;\&#8221; &#8211; the escape character</h3>
<p>When &#8220;\&#8221; appears in a custom format string, it simply escapes the next character so it does not get interpreted as a format specifier. For example, if the letter <code>s</code> appears in the string to be parsed, &#8220;\s&#8221; would represent it for parsing to ensure it does not get interpreted as the single character seconds custom format specifier.</p>
<h3>&#8220;%&#8221; &#8211; precedes a single character custom format specifier</h3>
<p>If you wish to use a single character custom format specifier you have several choices &#8211; prepend or append a space to it to ensure that it is not interpreted as a standard format string (otherwise it will be and if it is not a valid one a <code>FormatException</code> will be thrown). A downside to using a space in this manner is that one will be expected in the string to parse or will be output when converting to a string.</p>
<p>The alternative is to prepend &#8220;%&#8221; &#8211; this avoids the issue with spaces and serves as a special escape to allow for single character custom format specifiers.</p>
<hr />
<p>Take a look at the <a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx" title="Custom Date and Time format strings" target="_blank">documentation</a> for more detail.</p>
<p>I will not give examples for these, as the documentation contains plenty.</p>
<p>If you have specific questions about the contents of this post, please post them in the comments and I will answer to the best of my ability.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2011/12/13/date-and-time-format-strings-in-net-understanding-format-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Time format strings in .NET &#8211; InvariantCulture</title>
		<link>http://OdedCoster.com/blog/2011/11/27/date-and-time-format-strings-in-net-invariantculture/</link>
		<comments>http://OdedCoster.com/blog/2011/11/27/date-and-time-format-strings-in-net-invariantculture/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 13:46:25 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[Formatting]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=132</guid>
		<description><![CDATA[If you wish to have a deterministic format, but do not want to use a specific culture, you can use InvariantCulture. InvariantCulture represents no culture at all &#8211; it is associated with the English language, though no specific country/region. See Using the InvariantCulture Property on MSDN. Here is an example of its use: DateTime dt [...]]]></description>
				<content:encoded><![CDATA[<p>If you wish to have a deterministic format, but do not want to use a specific culture, you can use <code><a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.invariantculture.aspx" title="InvariantCulture" target="_blank">InvariantCulture</a></code>.</p>
<p><code>InvariantCulture</code> represents no culture at all &#8211; it is associated with the English language, though no specific country/region.</p>
<p>See <a href="http://msdn.microsoft.com/en-us/library/4c5zdc6a.aspx" title="Using the InvariantCulture property" target="_blank">Using the InvariantCulture Property</a> on MSDN.</p>
<p>Here is an example of its use:</p>
<pre>
DateTime dt = new DateTime(2011, 11, 21, 12, 34, 56);
Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2011/11/27/date-and-time-format-strings-in-net-invariantculture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Time format strings in .NET &#8211; CultureInfo</title>
		<link>http://OdedCoster.com/blog/2011/11/26/date-and-time-format-strings-in-net-cultureinfo/</link>
		<comments>http://OdedCoster.com/blog/2011/11/26/date-and-time-format-strings-in-net-cultureinfo/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 20:05:02 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[Formatting]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=128</guid>
		<description><![CDATA[As mentioned in my last post, the IFormatProvider interface in the context of DateTime is mostly used for formatting a DateTime to a specific representation and for parsing a string into a DateTime instance. Overloads that do not specify IFormatProvider So, what happens when overloads of ToString and the different Parse methods (Parse, TryParse, ParseExact [...]]]></description>
				<content:encoded><![CDATA[<p>As mentioned in my <a href="http://odedcoster.com/blog/2011/11/21/date-and-time-format-strings-in-net-iformatprovider/" title="IFormatProvider">last post</a>, the <code>IFormatProvider</code> interface in the context of <code>DateTime</code> is mostly used for formatting a <code>DateTime</code> to a specific representation and for parsing a string into a <code>DateTime</code> instance.</p>
<h2>Overloads that do not specify <code>IFormatProvider</code></h2>
<p>So, what happens when overloads of <code>ToString</code> and the different <code>Parse</code> methods (<code>Parse</code>, <code>TryParse</code>, <code>ParseExact </code>and <code>TryParseExact</code>) that <strong>don&#8217;t</strong> take an <code>IFormatProvider</code> instance are used?</p>
<p>To answer this, I will ask this question: what would the console output of the following lines of code?</p>
<pre>
DateTime dt = new DateTime(2011, 11, 21, 12, 34, 56);
Console.WriteLine(dt);
</pre>
<p>The answer is &#8211; it depends. It depends on the configured locale of the account that the application is executing under (see the Regional Settings and what the different Date and Time formats are configured as). The locale will determine what culture is used in.</p>
<p>So, if the user is in England, the result could be:</p>
<p><code>21/11/2011 12:34:56</code></p>
<p>If, however, the user is in the United States, the result could be:</p>
<p><code>11/21/2011 12:34:56 PM</code></p>
<p>As I have demonstrated, the <code>CultureInfo</code> instance associated with the current thread is the one used. Depending on the application context, either the <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx" title="Thread.CurrentCulture" target="_blank">Thread.CurrentCulture</a> or <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx" title="Thread.CurrentUICulture" target="_blank">Thread.CurrentUICulture</a> culture would be used.</p>
<p>For this reason, both <code>Thread.CurrentCulture</code> and <code>Thread.CurrentUICulture</code> should usually be changed at the same time to the same <code>CultureInfo</code>.</p>
<h2>Specifying an <code>IFormatProvider</code></h2>
<p>By specifying an <code>IFormatProvider</code> you can be explicit about over how <code>DateTime</code> instances get formatted and how strings get parsed into <code>DateTime </code>instances.</p>
<p>For example, here is how you would <strong>explicitly</strong> format a <code>DateTime </code>with a US culture:</p>
<pre>
DateTime dt = new DateTime(2011, 11, 21, 12, 34, 56);
Console.WriteLine(dt.ToString(CultureInfo.GetCultureInfo("en-US")));
</pre>
<p>And for the British version:</p>
<pre>
DateTime dt = new DateTime(2011, 11, 21, 12, 34, 56);
Console.WriteLine(dt.ToString(CultureInfo.GetCultureInfo("en-GB")));
</pre>
<p>The most amount of control would come with format strings, these do however interact with the culture &#8211; this will be covered in a future post.</p>
<h2>Some asides</h2>
<p>You can create your own cultures using &#8230; See <a href="http://msdn.microsoft.com/en-us/library/ms172469.aspx" title="How to: Create Custom Cultures" target="_blank">How to: Create Custom Cultures</a> on MSDN and the <a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.aspx" title="CultureAndRegionInfoBuilder" target="_blank">CultureAndRegionInfoBuilder</a> class.</p>
<p>Some locale settings can be changed &#8211; I will discuss some of that in a future post.</p>
<p>Here is good Microsoft FAQ about locales and languages &#8211; <a href="http://msdn.microsoft.com/en-us/goglobal/bb688174" title="FAQ - Locales and Languages" target="_blank">http://msdn.microsoft.com/en-us/goglobal/bb688174</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2011/11/26/date-and-time-format-strings-in-net-cultureinfo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Time format strings in .NET &#8211; IFormatProvider</title>
		<link>http://OdedCoster.com/blog/2011/11/21/date-and-time-format-strings-in-net-iformatprovider/</link>
		<comments>http://OdedCoster.com/blog/2011/11/21/date-and-time-format-strings-in-net-iformatprovider/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 20:32:38 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[Formatting]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=129</guid>
		<description><![CDATA[Several of the overloads of ToString and the different Parse methods (Parse, ParseExact, TryParse and TryParseExact) defined on DateTime take an IFormatProvider parameter. This interface defines a single method &#8211; GetFormat which takes a type and returns an object that provides formatting services for the specified type. When DateTime in concerned this object would be [...]]]></description>
				<content:encoded><![CDATA[<p>Several of the overloads of <code>ToString</code> and the different <code>Parse</code> methods (<code>Parse</code>, <code>ParseExact</code>, <code>TryParse</code> and <code>TryParseExact</code>) defined on <code>DateTime</code> take an <a href="http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx"><code>IFormatProvider</code></a> parameter.</p>
<p>This interface defines a single method &#8211; <code>GetFormat</code> which takes a type and returns an object that provides formatting services for the specified type. When <code>DateTime</code> in concerned this object would be an instance of the <a href="http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx"><code>DateTimeFormatInfo</code></a> class.</p>
<p>The <code>CultureInfo</code> class also implements the <code>IFormatProvider</code> interface and will also return a <code>DateTimeFormatInfo</code> instance when called in the context of <code>DateTime</code> formatting. This is important, as <code>CultureInfo</code> is the most common implementer of <code>IFormatProvider</code> that is used for formatting <code>DateTime</code> instances for display.</p>
<p>It is unlikely that you will ever need to implement <code>IFormatProvider</code> yourself, at least when <code>DateTime</code> formatting is concerned.</p>
<p>The most common usages of <code>IFormatProvider</code> with <code>DateTime</code> are to provide a culture sensitive display of the <code>DateTime</code> instance and to parse a string representing a <code>DateTime</code> into a <code>DateTime</code> instance. This will be the subject of the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2011/11/21/date-and-time-format-strings-in-net-iformatprovider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Time format strings in .NET &#8211; Introduction</title>
		<link>http://OdedCoster.com/blog/2011/11/20/date-and-time-format-strings-in-net-introduction/</link>
		<comments>http://OdedCoster.com/blog/2011/11/20/date-and-time-format-strings-in-net-introduction/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 20:09:26 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[Formatting]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=123</guid>
		<description><![CDATA[One of the most common misunderstandings I see on StackOverflow regarding the DateTime structure is the difference between the value of a DateTime instance and how it is displayed. A DateTime instance (say one representing midnight of March 26th 2011) has an internal representation that has no specific formatting &#8211; it is not something that [...]]]></description>
				<content:encoded><![CDATA[<p>One of the most common misunderstandings I see on StackOverflow regarding the <code>DateTime</code> structure is the difference between the value of a <code>DateTime</code> instance and how it is displayed.</p>
<p>A <code>DateTime</code> instance (say one representing midnight of March 26th 2011) has an internal representation that has no specific formatting &#8211; it is not something that will make sense to any human being in that form (this post is not about what exactly that representation is).</p>
<p>What this means is that every time you see a value for a <code>DateTime</code> instance, you are seeing this internal value after it has been formatted for human eyes. </p>
<p>How this formatted value comes to be is the subject of this blog series, starting with this introduction.</p>
<p>In future posts I will discuss the roles of <code>IFormatProvider</code> and format strings, Cultures and the Regional settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2011/11/20/date-and-time-format-strings-in-net-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Asking and answering questions on StackOverflow</title>
		<link>http://OdedCoster.com/blog/2010/09/15/asking-and-answering-questions-on-stackoverflow/</link>
		<comments>http://OdedCoster.com/blog/2010/09/15/asking-and-answering-questions-on-stackoverflow/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 19:04:04 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[StackOverflow]]></category>
		<category><![CDATA[jon skeet]]></category>
		<category><![CDATA[questions]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=117</guid>
		<description><![CDATA[The estimable Jon Skeet had posted a great blog about asking the perfect question, this is a follow on to his post on answering technical questions. Good stuff, most of which is generally applicable to any question/answer site and day to day questions and answer, a small portion is only relevant to StackOverflow.com.]]></description>
				<content:encoded><![CDATA[<p>The estimable <a href="http://msmvps.com/blogs/jon_skeet/default.aspx">Jon Skeet</a> had posted a great blog about <a href="http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx">asking the perfect question</a>, this is a follow on to his post on <a href="http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx">answering technical questions</a>.</p>
<p>Good stuff, most of which is generally applicable to any question/answer site and day to day questions and answer, a small portion is only relevant to <a href="http://stackoverflow.com">StackOverflow.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2010/09/15/asking-and-answering-questions-on-stackoverflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting good answers on StackOverflow &#8211; part 13 of n</title>
		<link>http://OdedCoster.com/blog/2010/08/10/getting-good-answers-on-stackoverflow-part-13-of-n/</link>
		<comments>http://OdedCoster.com/blog/2010/08/10/getting-good-answers-on-stackoverflow-part-13-of-n/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 12:42:11 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[StackOverflow]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=112</guid>
		<description><![CDATA[Tip #13 &#8211; What have you tried? when describing your problem, make sure to include details of what you already tried. This will help ensure that you do not get answers that go into more depth and that will suggest things you have not tried. Tip #1 &#8211; Ask a question Tip #2 &#8211; Be [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Tip #13 &#8211; What have you tried?</strong></p>
<p>when describing your problem, make sure to include details of what you already tried. This will help ensure that you do not get answers that go into more depth and that will suggest things you have not tried.</p>
<p><a href="http://OdedCoster.com/blog/2010/07/28/getting-good-answers-on-stackoverflow-part-1-of-n/">Tip #1</a> &#8211; Ask a question</p>
<p><a href="http://OdedCoster.com/blog/2010/07/29/getting-good-answers-on-stackoverflow-part-2-of-n/">Tip #2</a> &#8211; Be polite</p>
<p><a href="http://OdedCoster.com/blog/2010/07/30/getting-good-answers-on-stackoverflow-part-3-of-n/">Tip #3</a> &#8211; Ask one question</p>
<p><a href="http://OdedCoster.com/blog/2010/07/31/getting-good-answers-on-stackoverflow-part-4-of-n/">Tip #4</a> &#8211; Descriptive title</p>
<p><a href="http://OdedCoster.com/blog/2010/08/01/getting-good-answers-on-stackoverflow-part-5-of-n/">Tip #5</a> &#8211; Write in English</p>
<p><a href="http://OdedCoster.com/blog/2010/08/02/getting-good-answers-on-stackoverflow-part-6-of-n/">Tip #6</a> &#8211; Pertinent code samples</p>
<p><a href="http://OdedCoster.com/blog/2010/08/03/getting-good-answers-on-stackoverflow-part-7-of-n/">Tip #7</a> &#8211; Stay on topic</p>
<p><a href="http://OdedCoster.com/blog/2010/08/04/getting-good-answers-on-stackoverflow-part-8-of-n/">Tip #8</a> &#8211; Do some research</p>
<p><a href="http://OdedCoster.com/blog/2010/08/05/getting-good-answers-on-stackoverflow-part-9-of-n/">Tip #9</a> &#8211; Stay engaged</p>
<p><a href="http://OdedCoster.com/blog/2010/08/07/getting-good-answers-on-stackoverflow-part-10-of-n/">Tip #10</a> &#8211; What, not how</p>
<p><a href="http://OdedCoster.com/blog/2010/08/08/getting-good-answers-on-stackoverflow-part-11-of-n/">Tip #11</a> &#8211; Accept rate</p>
<p><a href="http://OdedCoster.com/blog/2010/08/09/getting-good-answers-on-stackoverflow-part-12-of-n/">Tip #12</a> &#8211; Code that shows the problem</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2010/08/10/getting-good-answers-on-stackoverflow-part-13-of-n/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting good answers on StackOverflow &#8211; part 12 of n</title>
		<link>http://OdedCoster.com/blog/2010/08/09/getting-good-answers-on-stackoverflow-part-12-of-n/</link>
		<comments>http://OdedCoster.com/blog/2010/08/09/getting-good-answers-on-stackoverflow-part-12-of-n/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 09:14:17 +0000</pubDate>
		<dc:creator>Oded Coster</dc:creator>
				<category><![CDATA[StackOverflow]]></category>

		<guid isPermaLink="false">http://OdedCoster.com/blog/?p=105</guid>
		<description><![CDATA[Tip #12 &#8211; Code that shows the problem When posting a code sample, make sure that it is representative of the problem you are having. This means that it needs to be syntacticly correct (otherwise, people will point out the syntax errors and not the problem you are trying to solve), if possible it should [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Tip #12 &#8211; Code that shows the problem</strong></p>
<p>When posting a code sample, make sure that it is representative of the problem you are having. This means that it needs to be syntacticly correct (otherwise, people will point out the syntax errors and not the problem you are trying to solve), if possible it should compile and it must clearly show the problem.</p>
<p>This will ensure that people will be able to easily reproduce the issue and answers will be relevant to the problem.</p>
<p><a href="http://OdedCoster.com/blog/2010/07/28/getting-good-answers-on-stackoverflow-part-1-of-n/">Tip #1</a> &#8211; Ask a question</p>
<p><a href="http://OdedCoster.com/blog/2010/07/29/getting-good-answers-on-stackoverflow-part-2-of-n/">Tip #2</a> &#8211; Be polite</p>
<p><a href="http://OdedCoster.com/blog/2010/07/30/getting-good-answers-on-stackoverflow-part-3-of-n/">Tip #3</a> &#8211; Ask one question</p>
<p><a href="http://OdedCoster.com/blog/2010/07/31/getting-good-answers-on-stackoverflow-part-4-of-n/">Tip #4</a> &#8211; Descriptive title</p>
<p><a href="http://OdedCoster.com/blog/2010/08/01/getting-good-answers-on-stackoverflow-part-5-of-n/">Tip #5</a> &#8211; Write in English</p>
<p><a href="http://OdedCoster.com/blog/2010/08/02/getting-good-answers-on-stackoverflow-part-6-of-n/">Tip #6</a> &#8211; Pertinent code samples</p>
<p><a href="http://OdedCoster.com/blog/2010/08/03/getting-good-answers-on-stackoverflow-part-7-of-n/">Tip #7</a> &#8211; Stay on topic</p>
<p><a href="http://OdedCoster.com/blog/2010/08/04/getting-good-answers-on-stackoverflow-part-8-of-n/">Tip #8</a> &#8211; Do some research</p>
<p><a href="http://OdedCoster.com/blog/2010/08/05/getting-good-answers-on-stackoverflow-part-9-of-n/">Tip #9</a> &#8211; Stay engaged</p>
<p><a href="http://OdedCoster.com/blog/2010/08/07/getting-good-answers-on-stackoverflow-part-10-of-n/">Tip #10</a> &#8211; What, not how</p>
<p><a href="http://OdedCoster.com/blog/2010/08/08/getting-good-answers-on-stackoverflow-part-11-of-n/">Tip #11</a> &#8211; Accept rate</p>
]]></content:encoded>
			<wfw:commentRss>http://OdedCoster.com/blog/2010/08/09/getting-good-answers-on-stackoverflow-part-12-of-n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
