Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.DateOnly: odniesienie praktyczne

System.DateOnly: odniesienie praktyczne: DateOnly reprezentuje datę kalendarzową bez czasu i strefy.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.DateOnly /* select a documented member or constructor */

DateOnly reprezentuje datę kalendarzową bez czasu i strefy.

Stosuj do urodzin, terminów i dni roboczych, które nie są chwilą na osi czasu.

Parsowanie i format zależą od kultury; do chwili potrzebujesz TimeOnly i strefy.

Zakres to 0001-01-01..9999-12-31; operacje poza nim zgłaszają wyjątek.

Kompletny program rzeczywiście używa System.DateOnly; oczekiwany stdout to dokładnie 2026-11-17.

Przykłady

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var date = new DateOnly(2026, 11, 17);
Console.WriteLine(date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));

Wynik

2026-11-17

Kompletny program rzeczywiście używa `System.DateOnly`; oczekiwany stdout to dokładnie `2026-11-17`.

Źródła