I have a text string that needs to become a DateTime
object:
Feb 10, 2012 at 16:33.29
This text does not change, but the software will run on many different devices with different DateTime
formats.
How can I set a custom DateTime
parser so that regardless of culture I will get a fully populated DateTime
object?
parse with CultureInfo.InvariantCulture?
Use
ParseExact
with a custom format string and the invariant culture:Here’s a custom format to match your example:
One thing has got nothing to do with the other.
DateTime.Parse(value, formatstr)
returns a DateTime.The DateTime does not have a format, unless you want to talk about how it's represented in memory. When you convert it to a string, you generally do it with an implicit or explicit format, once you have it is no longer a datetime...