Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.DateTime: odniesienie praktyczne

System.DateTime: odniesienie praktyczne: DateTime łączy datę i czas z Kind Utc, Local lub Unspecified.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

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

DateTime łączy datę i czas z Kind Utc, Local lub Unspecified.

Stosuj z jawnym Kind; dla zdarzeń między systemami często preferuj DateTimeOffset.

Kind nie przechowuje dowolnej strefy, a reguły DST tworzą czasy nieistniejące i dwuznaczne.

Zakres jest ograniczony; konwersje lokalne zależą od ustawień systemu i strefy.

Kompletny program rzeczywiście używa System.DateTime; oczekiwany stdout to dokładnie 2026-11-17T12:00:00.0000000Z.

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 instant = new DateTime(2026, 11, 17, 12, 0, 0, DateTimeKind.Utc);
Console.WriteLine(instant.ToString("O", CultureInfo.InvariantCulture));

Wynik

2026-11-17T12:00:00.0000000Z

Kompletny program rzeczywiście używa `System.DateTime`; oczekiwany stdout to dokładnie `2026-11-17T12:00:00.0000000Z`.

Źródła