Skip to content

OnixLabs.Core.DateTimeExtensions

Matthew Layton edited this page Nov 15, 2026 · 2 revisions

DateTimeExtensions Class

Extension methods for DateTime instances that split a DateTime into its date-only and time-only components.

Namespace OnixLabs.Core
Assembly OnixLabs.Core.dll (NuGet)
Inheritance object → DateTimeExtensions

Definition

[EditorBrowsable(EditorBrowsableState.Never)]
public static class DateTimeExtensions

Note This class is decorated with [EditorBrowsable(EditorBrowsableState.Never)], which keeps the container class itself out of IntelliSense lists while its extension methods remain fully usable on the receiver types. Bring the methods into scope with using OnixLabs.Core;.

Remarks

DateTimeExtensions provides concise conversions from DateTime to the modern DateOnly and TimeOnly types introduced in .NET 6.

Methods

Method Returns Description
ToDateOnly() DateOnly Obtains a DateOnly from the current DateTime.
ToTimeOnly() TimeOnly Obtains a TimeOnly from the current DateTime.

ToDateOnly()

public DateOnly ToDateOnly()

Obtains a DateOnly instance from the current DateTime instance.

Returns — The DateOnly instance obtained from the current DateTime.

ToTimeOnly()

public TimeOnly ToTimeOnly()

Obtains a TimeOnly instance from the current DateTime instance.

Returns — The TimeOnly instance obtained from the current DateTime.

DateTime now = new(2026, 5, 26, 14, 30, 0);
DateOnly date = now.ToDateOnly(); // 2026-05-26
TimeOnly time = now.ToTimeOnly(); // 14:30

See Also

ONIXLabs .NET Library


Clone this wiki locally