473,503 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in System.Globalization.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.InvariantCulture.Calendar;
DateTime theDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
DateTime.Now.Day, new GregorianCalendar() );
string dateBack = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")";

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 3236
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.InvariantCulture.Calendar
Dim theDate As DateTime = New DateTime(DateTime.Now.Year,
DateTime.Now.Month, DateTime.Now.Day, New GregorianCalendar)
Dim dateBack As String = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")"

Just curious why do you get the InvariantCulture's Calendar then pass New
GregorianCalendar 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.google.c om...
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() );
string dateBack = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")";

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.InvariantCulture.Calendar;
DateTime theDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
DateTime.Now.Day, new GregorianCalendar() );
string dateBack = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")";

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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
The InvariantCulture and Gregorian references slipped in as I tried
different options to make the dang thing work (see
System.Globilization.Calendar).

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

dateBack = theDate.ToString("D") + " (" + theDate.DayOfYear + ")";

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**************@TK2MSFTNGP10.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.InvariantCulture.Calendar
Dim theDate As DateTime = New DateTime(DateTime.Now.Year,
DateTime.Now.Month, DateTime.Now.Day, New GregorianCalendar)
Dim dateBack As String = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")"

Just curious why do you get the InvariantCulture's Calendar then pass New
GregorianCalendar 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.google.c om...
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() );
string dateBack = theDate.ToString("D") + " (" +
myCal.GetDayOfYear(theDate).ToString() + ")";

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
1453
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...
5
3924
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
3638
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...
2
2063
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...
11
7167
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...
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 =...
2
3124
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"...
0
3312
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...
0
1124
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");...
0
7188
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,...
0
7258
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,...
0
7313
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...
0
7441
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...
0
4663
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...
0
3156
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...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
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 ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.