Re: Converting a date string to a DateTime. Example please
- From: "Kim Hellan" <someone@xxxxxxxxxxx>
- Date: Thu, 13 Oct 2005 16:24:13 +0200
This is exactly what I have been looking for.
So simple, and without all that unnecessary IFormatProvider and CultureInfo
stuff.
THANK YOU!
"James Curran" <JamesCurran@xxxxxxxx> skrev i en meddelelse
news:uaazAB$zFHA.3896@xxxxxxxxxxxxxxxxxxxxxxx
>I think your main problem is that your format string is wrong:
>
> DateTime dt = DateTime.ParseExact(
> "13-10-05 10:19:26",
> "dd-MM-yy hh:mm:ss", null);
>
> Console.WriteLine(dt.ToString("F"));
>
> Prints: Thursday, October 13, 2005 10:19:26 AM
>
>
> Kim Hellan wrote:
>>>>> string strDate = "13-10-05 10:19:26";
>>>>> DateTime dtmDate = DateTime.Parse(strDate);
>>>>
>>>> Okay, lets say the date string is: "07-11-05 10:19:26".
>>>> How does the simple Parse() method above then know what is year,
>>>> month and day?
>>>
>>> It does not, therefore you should only use the DateTime.Parse (or if
>>> you use VBNet the than easier one for that CDate), if it comes from
>>> an input control as the textbox (and than it should be the installed
>>> culture way and go automaticly).
>>>
>>> If you use it on internet, than you should be sure that you have
>>> showed the datetime format mask beside the box.
>>>
>>> You can on Internet try to get the location from which it comes
>>> (that is not standard) and than assume the culture, however this is
>>> in my opinion real dangerous, because in by instance in Canada are
>>> two complete different date format paterns used.
>>>
>>> I hope this helps,
>>
>> Thank you, but my initial question still stands.
>> Can anybody give me a C# EXAMPLE of how to parse the "13-10-05
>> 10:19:26" string.
>> The string always have the format "DD-MM-YY hh:mm:ss" and the parsing
>> should work on ANY machine, ANYWHERE in the world, regardless of
>> culture/date settings on the computer used.
>>
>> Thank You!
>> Kim
>
> --
> Truth,
> James Curran [erstwhile-MVP]
> Home: www.noveltheory.com Work: www.njtheater.com
> Blog: www.honestillusion.com Day Job: www.partsearch.com
>
.
- Follow-Ups:
- Re: Converting a date string to a DateTime. Example please
- From: Mark Rae
- Re: Converting a date string to a DateTime. Example please
- References:
- Re: Converting a date string to a DateTime. Example please
- From: Mark Rae
- Re: Converting a date string to a DateTime. Example please
- From: Kim Hellan
- Re: Converting a date string to a DateTime. Example please
- From: James Curran
- Re: Converting a date string to a DateTime. Example please
- Prev by Date: Re: C++ Delphi C# ???
- Next by Date: Re: Can someone explain why switch syntax is the way it is?
- Previous by thread: Re: Converting a date string to a DateTime. Example please
- Next by thread: Re: Converting a date string to a DateTime. Example please
- Index(es):
Relevant Pages
|