Home

ParseExact

ParseExact is a method used in the .NET framework to convert a textual representation of a date and time into a DateTime value by requiring that the input string conform to a specified format exactly. It is commonly used when input must match a predefined pattern, rather than being flexibly parsed.

In .NET, the typical signature is DateTime.ParseExact(string s, string format, IFormatProvider provider), with overloads that accept

If the input does not match the format, ParseExact throws a FormatException. There is also TryParseExact, which

Format strings for ParseExact use a mix of standard and custom specifiers, such as yyyy, MM, dd,

Related concepts include Parse, TryParse, and ParseExact variants for DateTimeOffset and TimeSpan, all used for strict

an
array
of
accepted
formats,
a
DateTimeStyles
value,
and
a
provider.
The
method
uses
the
supplied
culture
information
to
interpret
culture-specific
components
such
as
month
names
and
calendar
rules,
and
it
can
work
with
standard
or
custom
format
specifiers.
returns
a
boolean
indicating
success
and
outputs
the
parsed
DateTime
without
throwing
exceptions.
If
the
parsed
value
falls
outside
the
allowable
DateTime
range,
an
OverflowException
is
thrown.
DateTimeStyles
can
be
supplied
to
adjust
parsing
behavior,
such
as
allowing
leading
white
space,
assuming
universal
time,
or
adjusting
the
resulting
kind.
HH,
mm,
ss,
and
K,
and
may
include
literals.
Escaping
or
quoting
enables
including
separators
or
fixed
text.
For
time
zones
or
offsets,
DateTimeOffset
with
ParseExact
can
be
used,
or
the
format
can
include
offset
specifiers
like
zzz.
To
minimize
locale
dependence,
InvariantCulture
is
a
common
provider.
or
culture-aware
parsing
of
textual
representations.