473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3234
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
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
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
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
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
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
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
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
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
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.