Convert.ToDateTime with different culture

L

Luigi

Hi all,
in my C# 2.0 application I have a test to perform a datetime conversion
(from string datatype), sort of:

Assert.AreEqual(Convert.ToDateTime("23/09/2008 14:31:45").....etc

The problem is that it works only in my machine, and not in the server.
The error is:

System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)

How can I set the culture (or something else) to be independent form
international settings?

Thanks a lot.
 
M

Martin Honnen

Luigi said:
Hi all,
in my C# 2.0 application I have a test to perform a datetime conversion
(from string datatype), sort of:

Assert.AreEqual(Convert.ToDateTime("23/09/2008 14:31:45").....etc

The problem is that it works only in my machine, and not in the server.
The error is:

System.FormatException : String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)

How can I set the culture (or something else) to be independent form
international settings?

Pass in a CultureInfo you want to use e.g.
Convert.ToDateTime("23/09/2008 14:31:45", new CultureInfo("en-GB"))
 
L

Luigi

Martin Honnen said:
Pass in a CultureInfo you want to use e.g.
Convert.ToDateTime("23/09/2008 14:31:45", new CultureInfo("en-GB"))

Perfect, thank you Martin.

Luigi
 

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