Home

TimeOnly

TimeOnly is a value type in the .NET framework that represents a time of day without an associated date. Introduced with DateOnly and TimeOnly to separate concerns between date and time, TimeOnly is part of the System namespace and is commonly used in scheduling, calendars, and any scenario where only the time portion matters.

TimeOnly stores hours, minutes, seconds, and fractional seconds within a 24-hour day. Its practical range spans

Creation and conversion: TimeOnly can be constructed directly, or derived from a DateTime or TimeSpan. It can

Formatting and parsing: TimeOnly supports standard and custom formatting strings for displaying times, and it can

Operations and usage: TimeOnly supports comparisons and basic arithmetic with TimeSpan values, enabling operations like adding

Availability and context: TimeOnly is part of .NET 6 and later, reflecting a broader design goal to

from
00:00:00.0000000
to
23:59:59.9999999.
The
type
is
immutable
and
designed
to
be
easy
to
compare,
format,
and
convert
with
other
time-related
types.
also
be
created
from
a
TimeSpan
that
represents
the
elapsed
time
since
midnight.
For
interoperability
with
date
components,
a
DateOnly
value
can
be
combined
with
a
TimeOnly
to
form
a
full
DateTime
via
a
ToDateTime
operation
on
DateOnly.
be
parsed
from
strings
using
parsing
methods
with
robust
error
handling
(such
as
TryParse
and
ParseExact
variants).
Accessors
provide
the
individual
components
such
as
Hour,
Minute,
Second,
and
Millisecond.
or
subtracting
time
intervals
without
tying
the
result
to
a
specific
date.
This
makes
TimeOnly
a
convenient
tool
for
time-of-day
calculations,
scheduling
logic,
and
user-facing
time
inputs.
reduce
misuse
of
DateTime
when
only
a
time-of-day
is
required.