|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Another DateTime.ParseExact issue?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/productfeedback/SearchResults.aspx?text=ParseExact&stype=1&fields=1&type=0&category=0&os=0&oslang=0&status=0&msstatus=0&resolution=0&chgdays=&validation=0&votes=&voterating=0&workarounds=False&attachments=False&product=0&version=0&creator=&createdWithin=&submissionlang=0&productlang=0 but none of the bugreports matches my problem. -- Jacek Kolonko 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. ==================================================== |
|||||||||||||||||||||||