By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,354 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,354 IT Pros & Developers. It's quick & easy.

DateTime.Parse problem with Time Format using period

P: n/a
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.
Feb 7 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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:
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.
Feb 7 '07 #2

P: n/a
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" <si********@newsgroup.nospamwrote in message
news:83**********************************@microsof t.com...
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.

Feb 7 '07 #3

P: n/a
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" <si********@newsgroup.nospamwrote in message
news:83**********************************@microsof t.com...
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.

Feb 7 '07 #4

P: n/a
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?
--
Tim Van Wassenhove <url:http://www.timvw.be/>
Feb 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.