<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>I'm not a Klingon (&lt;span style="font-family:pIqaD,code2000"&gt; &lt;/span&gt;) : Dates &amp;amp; Times</title><link>http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx</link><description>Tags: Dates &amp;amp; Times</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Japanese Calendars, How do I Test Support for Additional Eras?</title><link>http://blogs.msdn.com/shawnste/archive/2009/09/24/japanese-calendars-how-do-i-test-support-for-additional-eras.aspx</link><pubDate>Thu, 24 Sep 2009 21:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899125</guid><dc:creator>shawnste</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/9899125.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=9899125</wfw:commentRss><description>&lt;P&gt;The Japanese Calendar is labeled by the reign of the current emporer.&amp;nbsp; Windows has supported 4 Japanese calendar Eras, however in the future there may be more eras.&amp;nbsp; Realizing this, we've added support in Windows 7, Server 2008R2 &amp;amp; .Net v4 for additional Japanese Eras.&lt;/P&gt;
&lt;P&gt;There're a few things applications should know about extended Japanese Era support:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The first is that applications may see more than 4 eras!.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;The current era could end&lt;/LI&gt;
&lt;LI&gt;Future dates could change, moving from the current era to a new era.&amp;nbsp; (So "Heisei 71" could be "something 12" or something like that)&lt;/LI&gt;
&lt;LI&gt;The era numbers themselves could change, so the 1-4 era numbers shouldn't be relied upon.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Cool, so if we're being careful about all of those things, and are pretty sure we don't have any hard-coded dependencies on the Japanese Eras or when they are, how do we test it?&lt;/P&gt;
&lt;P&gt;On Windows 7 / Server 2008 R2 (beta) and CLRv4 (beta) Japanese era information can be found in the registry:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Windows Registry Editor Version 5.00&lt;/P&gt;
&lt;P&gt;[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras]&lt;BR&gt;"1868 01 01"="明治_明_Meiji_M"&lt;BR&gt;"1912 07 30"="大正_大_Taisho_T"&lt;BR&gt;"1926 12 25"="昭和_昭_Showa_S"&lt;BR&gt;"1989 01 08"="平成_平_Heisei_H"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Additional&amp;nbsp;eras can be added&amp;nbsp;just by adding an entry to the table.&amp;nbsp;&amp;nbsp;The format for the value "YYYY MM DD"="JE_AJE_EE_AEE" where the first day of the era is represented in the value name by&amp;nbsp;YYYY&amp;nbsp;for the year (gregorian), MM for the month, and DD for the day.&amp;nbsp; The value data contains the era strings, the "full" era name, followed by the abbreviated name (in Japanese), then the full name followed by the abbreviated name in English.&amp;nbsp; Each value is seperated by _ (underscore).&amp;nbsp; So in "YYYY MM DD"="JE_AJE_EE_AEE", JE represents the Japanese Era name, AJE represents the abbreviated Japanese Era.&amp;nbsp; EE represents the English Era name, and AEE represents the abbreviated English Era name.&lt;/P&gt;
&lt;P&gt;An example would be:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Windows Registry Editor Version 5.00&lt;/P&gt;
&lt;P&gt;[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras]&lt;BR&gt;"1868 01 01"="明治_明_Meiji_M"&lt;BR&gt;"1912 07 30"="大正_大_Taisho_T"&lt;BR&gt;"1926 12 25"="昭和_昭_Showa_S"&lt;BR&gt;"1989 01 08"="平成_平_Heisei_H"&lt;BR&gt;"2020 09 01"="仮名_仮_Test Era_X"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;(I'm not trying to make any predictions with the 2020, it's just a test number :)&amp;nbsp; Also remember this only works in Windows 7 and other newer products.&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;[Edited:&amp;nbsp; This is intended to support the possibility of a future era, not to enable older eras.&amp;nbsp; There's the potential that lots of stuff won't work correctly if eras prior to the existing 4 are added].&amp;nbsp; Also note that this registry key is pretty flexible.&amp;nbsp; If you want you could add a bunch of data for a bunch of eras &amp;lt; 1868.&amp;nbsp; (I don't have the data.)&amp;nbsp; That might break more stuff because then "Era 1" would turn into "Era 8" or something.&amp;nbsp; (Which is why I said not to depend on the Era number, it's pretty meaningless and arbitrary for us).&amp;nbsp; As noted, we only really intended to support adding new eras, not the historical ones.&amp;nbsp; Prior to 1870 or so the calendar was lunar not gregorian based, so conversions prior to then are pretty meaningless anyway.&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;Hope this is interesting,&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;Shawn&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899125" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item><item><title>DateTime.Parse() and DateTime.TryParse() fail in some cases</title><link>http://blogs.msdn.com/shawnste/archive/2007/05/10/datetime-parse-and-datetime-tryparse-fail-in-some-cases.aspx</link><pubDate>Fri, 11 May 2007 01:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2531466</guid><dc:creator>shawnste</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/2531466.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=2531466</wfw:commentRss><description>&lt;P&gt;DateTime.Parse and DateTime.TryParse fail in .Net 2.0 if the user locale date override has a space in it.&amp;nbsp; Ie: if its something like "M d yyyy".&amp;nbsp; .Net is getting tripped up over the space (we're working on a fix for SP1/Orcas).&lt;/P&gt;
&lt;P&gt;A workaround is to pass the culture without the user overrides as the format specifier.&amp;nbsp; This works because the non-overridden culture doesn't have the spaces that confuse the tokenizer, and the parser ignores spaces anyway.&lt;/P&gt;&lt;PRE&gt;using System;
using System.Globalization;

class Test
{
	static void Main()
	{
		String strDate = "01 Jan 2007";

		Console.WriteLine(strDate);
		Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
		Console.WriteLine(DateTime.Now.ToShortDateString());

		Console.WriteLine();
		
		DateTime dDate;

		// This works because the user defaults are ignored and the spaces are handled
		// by parse, which ignores spaces anyway.
		dDate = DateTime.Parse(strDate, new CultureInfo(CultureInfo.CurrentCulture.Name, false));
		Console.WriteLine(dDate);

		// This fails because the pattern has a space
		dDate = DateTime.Parse(strDate);
		Console.WriteLine(dDate);
	}
}
&lt;/PRE&gt;
&lt;P&gt;The output looks like this (if you set the user override for the date pattern in intl.cpl to "M d yyyy") &lt;/P&gt;&lt;PRE&gt;&amp;gt;csc test.cs
&amp;gt;test
01 Jan 2007
M d yyyy
5 10 2007

1 1 2007 12:00:00 AM

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the boun
ds of the array.
   at System.Globalization.DateTimeFormatInfo.InsertHash(TokenHashValue[] hashTa
ble, String str, TokenType tokenType, Int32 tokenValue)
   at System.Globalization.DateTimeFormatInfo.CreateTokenHashTable()
   at System.Globalization.DateTimeFormatInfo.Tokenize(TokenType TokenMask, Toke
nType&amp;amp; tokenType, Int32&amp;amp; tokenValue, __DTString&amp;amp; str)
   at System.__DTString.GetSeparatorToken(DateTimeFormatInfo dtfi)
   at System.DateTimeParse.Lex(DS dps, __DTString&amp;amp; str, DateTimeToken&amp;amp; dtok, Dat
eTimeRawInfo&amp;amp; raw, DateTimeResult&amp;amp; result, DateTimeFormatInfo&amp;amp; dtfi)
   at System.DateTimeParse.TryParse(String s, DateTimeFormatInfo dtfi, DateTimeS
tyles styles, DateTimeResult&amp;amp; result)
   at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyl
es styles)
   at System.DateTime.Parse(String s)
   at Test.Main()&lt;/PRE&gt;
&lt;P&gt;Hopefully this is helpful to people who've run into this problem.&amp;nbsp; Of course another workaround is just to use a different date seperator.&amp;nbsp; Of course parsing is generally tricky, particularly if you're asking for the user culture and data.&amp;nbsp; See &lt;A href="http://blogs.msdn.com/shawnste/archive/2005/04/05/405694.aspx" mce_href="http://blogs.msdn.com/shawnste/archive/2005/04/05/405694.aspx"&gt;Culture data shouldn't be considered stable (except for Invariant)&lt;/A&gt;&amp;nbsp;for a list of some of the issues.&amp;nbsp; In general a calendar control is more reliable when getting data from a user.&lt;/P&gt;
&lt;P&gt;'til next time,&lt;/P&gt;
&lt;P&gt;Shawn&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2531466" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnste/archive/tags/Custom+Cultures+_2F00_+Locales+_2F00_+CultureInfo/default.aspx">Custom Cultures / Locales / CultureInfo</category><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item><item><title>DateTime.Parse() fails when separator is " " (space) in .Net v2.0 RTM</title><link>http://blogs.msdn.com/shawnste/archive/2007/03/19/datetime-parse-fails-when-separator-is-space-in-net-v2-0-rtm.aspx</link><pubDate>Mon, 19 Mar 2007 21:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1914151</guid><dc:creator>shawnste</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/1914151.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=1914151</wfw:commentRss><description>&lt;P&gt;In Whidbey (Microsoft.Net v2.0), DateTime.Parse() throws an exception if the date separator is a space.&amp;nbsp; This was fixed in future QFEs, including the Whidbey Vista release, so you'll only see this on XP, 2003, etc and not on Vista.&lt;/P&gt;
&lt;P&gt;This is fixed in future versions, so if you apply most any QFE to .Net 2.0 RTM this bug'll be fixed.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1914151" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item><item><title>How do I get localization in JScript (JavaScript) in IE7?</title><link>http://blogs.msdn.com/shawnste/archive/2006/09/05/741871.aspx</link><pubDate>Wed, 06 Sep 2006 02:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:741871</guid><dc:creator>shawnste</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/741871.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=741871</wfw:commentRss><description>&lt;P&gt;I ran into an interesting problem with a Vista sidebar calendar gadget.&amp;nbsp; It seems that it is not exactly trivial to find out interesting NLS data like localized month names, first day of week, etc. from JScript.&lt;/P&gt;
&lt;P&gt;Eventually I found a workaround for some of the data.&amp;nbsp; VBScript has&amp;nbsp;MonthName,&amp;nbsp;WeekDayName and WeekDay functions that can be used for some of the data I was looking for.&amp;nbsp; These can be wrapped in VBScript functions which JScript can then call from the same page.&amp;nbsp; I calculated FirstDayOfWeek information by using the WeekDay function for a known date.&lt;/P&gt;
&lt;P&gt;These are the helpers that I ended up with:&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;&amp;lt;script language="VBscript"&amp;gt;&lt;BR&gt;' Helper functions so we can do this in JScript as well&lt;BR&gt;Function MyMonthName(month)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyMonthName = MonthName(month)&lt;BR&gt;End Function&lt;/P&gt;
&lt;P&gt;Function MyAbbrevMonthName(month)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyAbbrevMonthName = MonthName(month, True)&lt;BR&gt;End Function&lt;/P&gt;
&lt;P&gt;Function MyDayName(day)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyDayName = WeekDayName(day)&lt;BR&gt;End Function&lt;/P&gt;
&lt;P&gt;Function MyAbbrevDayName(day)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyAbbrevDayName = WeekDayName(day, True)&lt;BR&gt;End Function&lt;/P&gt;
&lt;P&gt;' Get First Day of Week where 1 is Sunday, 2 is Monday, etc.&lt;BR&gt;Function FirstDayOfWeek()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim MyDate&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyDate = DateSerial(2002, 9, 1) ' A Sunday&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstDayOfWeek = (9 - WeekDay(MyDate, 0))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if FirstDayOfWeek = 8 then FirstDayOfWeek = 1&lt;BR&gt;End Function&lt;/P&gt;&lt;P&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;/PRE&gt;
&lt;P&gt;Unfortunately some items like Shortest Day Names and Month/Year patterns can't be retrieved this way, but I was able to solve most of my problem.&amp;nbsp; The attached CalendarData.html uses these helper functions to dump the values I was interested in using both VBScript and JScript.&lt;/P&gt;
&lt;P&gt;I also embedded the HTML here, so here's the output, hope this is interesting:&lt;/P&gt;
&lt;script language="VBscript"&gt;

' Helper functions so we can do this in JScript as well
Function MyMonthName(month)
	MyMonthName = MonthName(month)
End Function

Function MyAbbrevMonthName(month)
	MyAbbrevMonthName = MonthName(month, True)
End Function

Function MyDayName(day)
	MyDayName = WeekDayName(day)
End Function

Function MyAbbrevDayName(day)
	MyAbbrevDayName = WeekDayName(day, True)
End Function

' Get First Day of Week where 1 is Sunday, 2 is Monday, etc.
Function FirstDayOfWeek()
	Dim MyDate
	MyDate = DateSerial(2002, 9, 1) ' A Sunday
	FirstDayOfWeek = (9 - WeekDay(MyDate, 0))
	if FirstDayOfWeek = 8 then FirstDayOfWeek = 1
End Function

' Dump them from VBScript
document.write("&lt;h3&gt;Dumping calendar data from VBScript:&lt;/h3&gt;")

' Show month names
document.write("Month Names&lt;dl compact&gt;")

Dim i
for i = 1 to 12
	document.write("&lt;dt&gt;")
	document.write(MonthName(i, True))
	document.write(" &lt;dd&gt;")
	document.write(MonthName(i))
next

' Show Day Names
document.write("&lt;/dl&gt;Day Names&lt;dl compact&gt;")
for i = 1 to 7
	document.write("&lt;dt&gt;")
	document.write(WeekDayName(i, True))
	document.write(" &lt;dd&gt;")
	document.write(WeekDayName(i))
next
document.write("&lt;/dl&gt;")

'First Day of Week
document.write("First Day Of Week: ")
document.write(FirstDayOfWeek())
document.write(" = ")
document.write(WeekDayName(FirstDayOfWeek(), False, 1))
document.write("&lt;br&gt;")
&lt;/Script&gt;


&lt;Script language="JScript"&gt;
// Dump them from JScript
document.write("&lt;h3&gt;Dumping calendar data from JScript:&lt;/h3&gt;");

// Show month names
document.write("Month Names&lt;dl compact&gt;")
for (i = 1; i &lt; 12; i++)
{
	document.write("&lt;dt&gt;");
	document.write(MyAbbrevMonthName(i));
	document.write(" &lt;dd&gt;");
	document.write(MyMonthName(i));
}
document.write("&lt;/dl&gt;");


// Show day names
document.write("Day Names&lt;dl compact&gt;")
for (i = 1; i &lt; 7; i++)
{
	document.write("&lt;dt&gt;");
	document.write(MyAbbrevDayName(i));
	document.write(" &lt;dd&gt;");
	document.write(MyDayName(i));
}
document.write("&lt;/dl&gt;");

// First Day of Week
document.write("First Day Of Week: ");
document.write(FirstDayOfWeek());
document.write(" = ");
document.write(MyDayName(FirstDayOfWeek()));
document.write("&lt;br&gt;");


&lt;/Script&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=741871" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shawnste/attachment/741871.ashx" length="2263" type="text/html" /><category domain="http://blogs.msdn.com/shawnste/archive/tags/Custom+Cultures+_2F00_+Locales+_2F00_+CultureInfo/default.aspx">Custom Cultures / Locales / CultureInfo</category><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item><item><title>ISO 8601 Week of Year format in Microsoft .Net</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx</link><pubDate>Wed, 25 Jan 2006 02:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:517178</guid><dc:creator>shawnste</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/517178.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=517178</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;Several people have noticed that &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcalendarclassgetweekofyeartopic.asp" mce_href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcalendarclassgetweekofyeartopic.asp"&gt;Calendar.GetWeekOfYear()&lt;/A&gt;&amp;nbsp;is almost like the &lt;A href="http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html" mce_href="http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html"&gt;ISO 8601 week&lt;/A&gt;&amp;nbsp;when passed &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcalendarweekruleclasstopic.asp" mce_href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcalendarweekruleclasstopic.asp"&gt;CalendarWeekRule.FirstFourDayWeek&lt;/A&gt;&amp;nbsp;and &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdayofweekclasstopic.asp" mce_href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdayofweekclasstopic.asp"&gt;DayOfWeek.Monday&lt;/A&gt;, however it is a little bit different.&amp;nbsp; Specifically ISO 8601 always has 7 day weeks.&amp;nbsp; If the first partial week of a year doesn't contain Thursday, then it is counted as the last week of the previous year.&amp;nbsp; Likewise, if the last week of the previous year doesn't contain Thursday then its treated like the first week of the next year.&amp;nbsp; GetWeekOfYear() has the first behavior, but not the second.&amp;nbsp; Ie:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class="" cellSpacing=5&gt;
&lt;TBODY&gt;
&lt;TR style="BACKGROUND-COLOR: #d3d3d3"&gt;
&lt;TH class=""&gt;&lt;FONT face=Arial size=2&gt;Date&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face=Arial size=2&gt;Day&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face=Arial size=2&gt;GetWeekOfYear&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face=Arial size=2&gt;ISO 8601 Week&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;12/31/2000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;Sunday&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;52 of 2000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;52 of 2000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;1/1/2001&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;Monday&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;1 of 2001&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;1 of 2001&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;1/1/2005&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;Saturday&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="" style="BACKGROUND-COLOR: #ffc0c0"&gt;&lt;FONT face=Arial size=2&gt;53 of 2004&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="" style="BACKGROUND-COLOR: #ffc0c0"&gt;&lt;FONT face=Arial size=2&gt;53 of 2004&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;12/31/2007&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;Monday&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face=Arial size=2&gt;53 of 2007&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="" style="BACKGROUND-COLOR: #ffc0c0"&gt;&lt;FONT face=Arial size=2&gt;1 of 2008&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Notice that the ISO&amp;nbsp;8601 week at the end of 2007 is different than the GetWeekOfYear() week.&amp;nbsp; For GetWeekOfYear(), both the last week and the first week have fewer than 7 days.&amp;nbsp; Also notice that even though its a 2007&amp;nbsp;date, its considered the first week of 2008.&amp;nbsp; Similarly the first day of 2005 is considered to be the last week of 2004 by either method.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;A simple workaround to consistently get the ISO 8601 week is to realize that consecutive days Monday through Sunday in ISO 8601 weeks all have the same week #.&amp;nbsp; So Monday has the same week # as Thursday.&amp;nbsp; Since Thursday is the critical day for determining when the week starts each year my solution is to add 3 days if the day is Monday, Tuesday or Wednesday.&amp;nbsp; The adjusted days are still in the same week, and use values that GetWeekOfYear and ISO 8601 agree on. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Note that if the requirement is to compute a date in the 2004W536 form, the code will still have to detect that a week 53 in January means that we need to decrement the year by 1, and a week 1 in December requires incrementing the year by 1.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Here's my example.&amp;nbsp; I made this a complete program, however GetIso8601WeekOfYear() is the worker function.&amp;nbsp; I used a static calendar, which probably isn't necessary.&amp;nbsp; Bala pointed out that one could derive a class from GregorianCalendar and override GetWeekOfYear(), but I'm not sure what the repercussions of using such a calendar elsewhere would be.&amp;nbsp; You can try it if you want, but for now this sample is just a simple static method.&amp;nbsp; Main is just here to run through a bunch of days and show when the week calculations differ.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;using System;&lt;BR&gt;using System.Globalization;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;class Test&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Need a calendar.&amp;nbsp; Culture's irrelevent since we specify start day of week&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static Calendar cal = CultureInfo.InvariantCulture.Calendar;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This presumes that weeks start with Monday.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Week 1 is the 1st week of the year with a Thursday in it.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static int GetIso8601WeekOfYear(DateTime time)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Seriously cheat.&amp;nbsp; If its Monday, Tuesday or Wednesday, then it'll &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // be the same week# as whatever Thursday, Friday or Saturday are,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // and we always get those right&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DayOfWeek day = cal.GetDayOfWeek(time);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (day &amp;gt;= DayOfWeek.Monday &amp;amp;&amp;amp; day &amp;lt;= DayOfWeek.Wednesday)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time = time.AddDays(3);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Return the week of our adjusted day&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return cal.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 1/1/1990 starts on a Monday&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime dt = new DateTime(1990, 1, 1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Starting at " + dt + " day: " + cal.GetDayOfWeek(dt) + " Week: " +GetIso8601WeekOfYear(dt));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; 100000; i++)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int days = 0; days &amp;lt; 7; dt=dt.AddDays(1), days++)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (GetIso8601WeekOfYear(dt) != cal.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("Iso Week " + GetIso8601WeekOfYear(dt) + &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " GetWeekOfYear: " + cal.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) + &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " Date: " + dt + " Day: " + cal.GetDayOfWeek(dt));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=517178" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item><item><title>Custom Time Zones in Windows</title><link>http://blogs.msdn.com/shawnste/archive/2006/01/20/515553.aspx</link><pubDate>Sat, 21 Jan 2006 00:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:515553</guid><dc:creator>shawnste</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/shawnste/comments/515553.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnste/commentrss.aspx?PostID=515553</wfw:commentRss><description>&lt;P&gt;Someone asked about adding the &lt;A href="http://www.twinsun.com/tz/tz-link.htm"&gt;"Olson"&lt;/A&gt; database of timezones to Windows, and I learned about tzedit.exe and the registry keys.&amp;nbsp; Tzedit.exe is a simple tool that allows you to add or edit the time zone registry entries, which live in the registry at HKLM\Software\Microsoft\Windows NT\CurrentVersion\Time Zones\...&lt;/P&gt;
&lt;P&gt;Windows &lt;A href="http://support.microsoft.com/?kbid=317211"&gt;KB 317211&lt;/A&gt;&amp;nbsp;discusses various ways of changing time zone data, but the gist of it is that keys are added or removed from the Time Zones key in the registry.&amp;nbsp; If one wanted to put the whole Olson database in the registry it should be reasonably straightforward to make a tool to do so (but your time zone drop down would get pretty big so I'm not sure how it'd impact usability).&lt;/P&gt;
&lt;P&gt;The cryptic part of the registry information is the "TZI" value, but &lt;A href="http://support.microsoft.com/kb/221542/"&gt;KB 221542&lt;/A&gt; provides a VB program to muck with time zone data, which defines the following type to describe this data, so that should be helpful.&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=-1&gt;Private Type REGTIMEZONEINFORMATION&lt;BR&gt;&amp;nbsp;&amp;nbsp; Bias As Long&lt;BR&gt;&amp;nbsp;&amp;nbsp; StandardBias As Long&lt;BR&gt;&amp;nbsp;&amp;nbsp; DaylightBias As Long&lt;BR&gt;&amp;nbsp;&amp;nbsp; StandardDate As SYSTEMTIME&lt;BR&gt;&amp;nbsp;&amp;nbsp; DaylightDate As SYSTEMTIME&lt;BR&gt;End Type&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So far I'm not aware of any tool that actually imports the Olson data, but by putting together these pieces it should be possible.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;It should be noted that time zone data isn't simple to work with.&amp;nbsp; Governments keep changing their rules for things like daylight savings time&amp;nbsp;and what the time zone offset should be in which places.&amp;nbsp; Also these KB articles are referring to shipping versions of Windows, I'm not sure how the behavior may differ in Windows Vista, so caveat programmer.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=515553" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnste/archive/tags/Custom+Cultures+_2F00_+Locales+_2F00_+CultureInfo/default.aspx">Custom Cultures / Locales / CultureInfo</category><category domain="http://blogs.msdn.com/shawnste/archive/tags/Dates+_2600_amp_3B00_+Times/default.aspx">Dates &amp;amp; Times</category></item></channel></rss>