Home All Groups Group Topic Archive Search About

How to determine a string is in valid dateTime format

Author
18 Apr 2007 8:20 PM
Andrew
Hello, friends,

What is the best way to determine a string is in valid dateTime format?

Thanks a lot.

Author
18 Apr 2007 8:34 PM
Scott M.
Try casting it to a DateTime inside of a try...catch?  Use RegEx?



Show quote
"Andrew" <And***@discussions.microsoft.com> wrote in message
news:8484F4F8-3DC4-4882-BEA4-914AF56DDEEF@microsoft.com...
> Hello, friends,
>
> What is the best way to determine a string is in valid dateTime format?
>
> Thanks a lot.
Author
18 Apr 2007 8:38 PM
Alex Meleta
DateTime.TryParse() and such.

WBR, Alex Meleta
Blog: http://devkids.blogspot.com

-----Original Message-----
From: Andrew [mailto:And***@discussions.microsoft.com]
Posted At: Donnerstag, 19. April 2007 00:20
Posted To: microsoft.public.dotnet.framework
Conversation: How to determine a string is in valid dateTime format
Subject: How to determine a string is in valid dateTime format

Hello, friends,

What is the best way to determine a string is in valid dateTime format?

Thanks a lot.
Author
18 Apr 2007 9:52 PM
Andrew
Thank you guys. I used DateTime.TryParse().

Also, another question: How to quickly convert a collection into an array?

Thanks again.
Author
18 Apr 2007 10:21 PM
Aleksander Polak
> Also, another question: How to quickly convert a collection into an array?

It depends on the collection. ArrayList and List<T> have a parameterless
ToArray method, which creates an array containing elements from the
collection. In addition, ICollection and ICollection<T> exposes a CopyTo
method, which can be used in the following manner:

Widget[] arr = new Widget[coll.Count];
coll.CopyTo(arr, 0);

--
Aleksander Polak

AddThis Social Bookmark Button