Connecting Tech Pros Worldwide Help | Site Map

DateTime.Parse problem with Time Format using period

=?Utf-8?B?c2lwcHl1Y29ubg==?=
Guest
 
Posts: n/a
#1: Feb 7 '07
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.
=?Utf-8?B?c2VrYXI=?=
Guest
 
Posts: n/a
#2: Feb 7 '07

re: DateTime.Parse problem with Time Format using period


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



"sippyuconn" wrote:
Quote:
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.
Ollie Riches
Guest
 
Posts: n/a
#3: Feb 7 '07

re: DateTime.Parse problem with Time Format using period


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" <sippyuconn@newsgroup.nospamwrote in message
news:835251C8-1FFB-4B9B-90A1-0B25A65D9DA6@microsoft.com...
Quote:
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.

Stoitcho Goutsev \(100\)
Guest
 
Posts: n/a
#4: Feb 7 '07

re: DateTime.Parse problem with Time Format using period


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.


--
Stoitcho Goutsev (100)

"sippyuconn" <sippyuconn@newsgroup.nospamwrote in message
news:835251C8-1FFB-4B9B-90A1-0B25A65D9DA6@microsoft.com...
Quote:
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.

Tim Van Wassenhove
Guest
 
Posts: n/a
#5: Feb 7 '07

re: DateTime.Parse problem with Time Format using period


sippyuconn schreef:
Quote:
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?


--
Tim Van Wassenhove <url:http://www.timvw.be/>
Closed Thread