473,651 Members | 2,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in System.Globaliz ation.Calendar class?

Consider the following:

As I post this, it is June 11th, 2004.
My desk calendar tells me it is day 163 of the current year.

This code:

Calendar myCal = CultureInfo.Inv ariantCulture.C alendar;
DateTime theDate = new DateTime(DateTi me.Now.Year, DateTime.Now.Mo nth,
DateTime.Now.Da y, new GregorianCalend ar() );
string dateBack = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")";

returns Friday, June 11, 2004 (150)

Obviously, the day of the year is incorrect. What am I doing wrong?

TIA.

greyseal
Jul 21 '05 #1
3 3255
greyseal,
Your code converted to VB.NET produces:

dateBack "Friday, June 11, 2004 (163)" String

Under VB.NET 2003 on Windows XP Pro with regional settings for the U.S.

Dim myCal As Calendar = CultureInfo.Inv ariantCulture.C alendar
Dim theDate As DateTime = New DateTime(DateTi me.Now.Year,
DateTime.Now.Mo nth, DateTime.Now.Da y, New GregorianCalend ar)
Dim dateBack As String = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")"

Just curious why do you get the InvariantCultur e's Calendar then pass New
GregorianCalend ar to DateTime? I would expect you should use the same
calendar in both cases!

Hope this helps
Jay

"greyseal" <gr************ *@hotmail.com> wrote in message
news:ee******** *************** ***@posting.goo gle.com...
Consider the following:

As I post this, it is June 11th, 2004.
My desk calendar tells me it is day 163 of the current year.

This code:

Calendar myCal = CultureInfo.Inv ariantCulture.C alendar;
DateTime theDate = new DateTime(DateTi me.Now.Year, DateTime.Now.Mo nth,
DateTime.Now.Da y, new GregorianCalend ar() );
string dateBack = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")";

returns Friday, June 11, 2004 (150)

Obviously, the day of the year is incorrect. What am I doing wrong?

TIA.

greyseal

Jul 21 '05 #2
greyseal <gr************ *@hotmail.com> wrote:
Consider the following:

As I post this, it is June 11th, 2004.
My desk calendar tells me it is day 163 of the current year.

This code:

Calendar myCal = CultureInfo.Inv ariantCulture.C alendar;
DateTime theDate = new DateTime(DateTi me.Now.Year, DateTime.Now.Mo nth,
DateTime.Now.Da y, new GregorianCalend ar() );
string dateBack = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")";

returns Friday, June 11, 2004 (150)

Obviously, the day of the year is incorrect. What am I doing wrong?


Not sure - when I run the code, I get back the correct answer.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
The InvariantCultur e and Gregorian references slipped in as I tried
different options to make the dang thing work (see
System.Globiliz ation.Calendar) .

I finally got back to the project today and decided to try the
following:

dateBack = theDate.ToStrin g("D") + " (" + theDate.DayOfYe ar + ")";

Worked like a champ - how'd I miss that?

Go figure.

greyseal

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:<ux******* *******@TK2MSFT NGP10.phx.gbl>. ..
greyseal,
Your code converted to VB.NET produces:

dateBack "Friday, June 11, 2004 (163)" String

Under VB.NET 2003 on Windows XP Pro with regional settings for the U.S.

Dim myCal As Calendar = CultureInfo.Inv ariantCulture.C alendar
Dim theDate As DateTime = New DateTime(DateTi me.Now.Year,
DateTime.Now.Mo nth, DateTime.Now.Da y, New GregorianCalend ar)
Dim dateBack As String = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")"

Just curious why do you get the InvariantCultur e's Calendar then pass New
GregorianCalend ar to DateTime? I would expect you should use the same
calendar in both cases!

Hope this helps
Jay

"greyseal" <gr************ *@hotmail.com> wrote in message
news:ee******** *************** ***@posting.goo gle.com...
Consider the following:

As I post this, it is June 11th, 2004.
My desk calendar tells me it is day 163 of the current year.

This code:

Calendar myCal = CultureInfo.Inv ariantCulture.C alendar;
DateTime theDate = new DateTime(DateTi me.Now.Year, DateTime.Now.Mo nth,
DateTime.Now.Da y, new GregorianCalend ar() );
string dateBack = theDate.ToStrin g("D") + " (" +
myCal.GetDayOfY ear(theDate).To String() + ")";

returns Friday, June 11, 2004 (150)

Obviously, the day of the year is incorrect. What am I doing wrong?

TIA.

greyseal

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
1464
by: Sput | last post by:
I am thoroughly frustrated with these seemingly unchangable settings in C#. For example, fetching data from database sorted by date returns wrong order (would be correct if I was using american date system). Same goes for sorting datagrid (sorts dates and decimal numbers - ie 31.12.2004 is sorted by first number instead of second and 100.000,00 is treated as text ). Is there a simple way of changing this or am I to write my own sorting...
5
3940
by: Abdolhosein Vakilzadeh Ebrahimi | last post by:
Is there any way to construct a System.DateTime which doesn't check year, month and day to be in correct range== no validation? Thanks A.V.Ebrahimi
14
3665
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be writing okay, but it's failing to parse. I've tried changing the regional & language settings in my...
2
2073
by: Eric | last post by:
I use the the calendar in VB.NET and then the days are displayed in Dutch. When I run in IE5 , days are in English. I changed the preferred language in IE, no change. I do not understand why VB.NET shows the days in the calendar control in dutch anyway. I set the language option in VB.NET (Tools/Options/InternationalSettings to Same as MS Office. which is English in my case. Appreciate any advice where to look for the logic to get this...
11
7221
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
3
328
by: greyseal | last post by:
Consider the following: As I post this, it is June 11th, 2004. My desk calendar tells me it is day 163 of the current year. This code: Calendar myCal = CultureInfo.InvariantCulture.Calendar; DateTime theDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, new GregorianCalendar() );
2
3132
by: jason | last post by:
DOTNET 2.0 VS 2005. My client is saying August 13,2006.. julian date should equal 225. Here's what I'm doing: <%@ Import Namespace="system.globalization" %> <script language="VB" runat="server">
0
3323
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I would like to get the code for connecting the javascript to asp.net page... Please help me... The javascript code is as follows..
0
1140
by: Jedediah Marcus | last post by:
I would like to parse a hebrew date into a System::DateTime variable: System::Globalization::CultureInfo ^CulInfo = gcnew System::Globalization::CultureInfo("he-IL"); CulInfo->DateTimeFormat->Calendar = gcnew System::Globalization::HebrewCalendar; CulInfo->DateTimeFormat->DateSeparator = " "; System::DateTime dt;
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.