DateTime.Parse problem with Time Format using period

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am having a problem formatting a string when the time is in format
hh.mm.ss - used in Europe

Parse seems ok when the date uses "/" or "." as seperator
but I get an exception when time uses "." as seperator as used in Europe

I have US regional setting and I have tried switching my regional setting to
Europe
with no luck

Any ideas on what I an doing wrong???

Thanks

DateTime dt = DateTime.Parse("10/10/2007" + " " + "12:10:00"); --> OK
DateTime dt = DateTime.Parse("10.10.2007" + " " + "12:10:00"); --> OK


DateTime dt = DateTime.Parse("10.10.2007" + " " + "12.10.00"); -->Problem
DateTime dt = DateTime.Parse("10/10/2007" + " " + "12.10.00"); -->Problem

Exception
String was not recognized as a valid DateTime.
 
hi sippyuconn ,
ur using this format in time( 12.10.00 )-->ok
Actualy we can't use that format ,we can represent ( 12:10:00 )
then only it will run .
ok
 
you use a DateTimeFormatInfo object, something like:

string str1 = "10/10/2007" + " " + "12.10.00";
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.TimeSeparator = ".";
DateTime dt1 = DateTime.Parse(str1, dtfi);

HTH

Ollie Riches
 
sippyuconn,
Why do you think 12.10.00 is valid time format in Europe?
European countries uses ':' for time separator. '.' can be used only to show
fractions of a second.
 
sippyuconn schreef:
Parse seems ok when the date uses "/" or "." as seperator
but I get an exception when time uses "." as seperator as used in Europe

Use DateTime.ParseExact instead?
 
Back
Top