If my string is 26/01/2011 00:14:00
but my computer set United state format (AM:PM)
How to convert my string into Datetime
?
I try Convert.ToDateTime()
but it cause error.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
As the others have said, you can use DateTime.TryParseExact, but you also seem to have a European culture format in your date. It might not hurt to make an attempt to use that to perform the conversion:
Use DateTime.ParseExact or DateTime.TryParseExact. If you have to accept multiple possible datetime formats, both of those methods have overloads that take an array of format strings.
As far as that format, it looks like "dd/mm/yyyy HH:MM:ss"
I use DateTime.Tryparse - that way you can catch and handle a failure gracefully:
http://msdn.microsoft.com/en-us/library/system.datetime.tryparse.aspx