Another DateTime.ParseExact issue?

G

Guest

Hi.

Does anyone know if there is a know bug in DateTime.ParseExact that makes it
unable to read DateTime-formatted strings using the same format and culture
parameters?

The following code will ilustrate my problem:

using System;
using System.Globalization;
using System.Text;

namespace DateTimeSample
{
class Program
{
static void Main(string[] args)
{
String format = "ddMMMyyy HH:mm";
IFormatProvider provider = CultureInfo.CurrentCulture;
//en-GB here
String text = DateTime.Now.ToString(format, provider);
//text=18May2006 15:24
DateTime dt = DateTime.ParseExact(text, format, provider);
//Exception {"String was not recognized as a valid DateTime."}
}
}
}

If so - is there a good workaround for this particular format (assuming
CurrentCulture changes, it is used in an international application).

I looked through
http://lab.msdn.microsoft.com/produ...createdWithin=&submissionlang=0&productlang=0 but none of the bugreports matches my problem.
 
L

Linda Liu [MSFT]

Hi Jacek,

Thank you for posting.

The value of the "format" variable in your program should be "ddMMMyyyy
HH:mm". For the part of year in the datetime string("18May2006 15:24") has
four digital numbers("2006"), the format text for parsing a string to a
datetime value should be "yyyy" in the year part.

Hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top