База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / C#

System.DateTime: практическа справка

System.DateTime: практическа справка: DateTime съчетава дата и час с Kind Utc, Local или Unspecified.

Версия: .NET API; verified on .NET 10.0.14

Синтаксис

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

DateTime съчетава дата и час с Kind Utc, Local или Unspecified.

Използвайте го с явен Kind; DateTimeOffset често е по-безопасен за събития между системи.

Kind не съхранява произволна часова зона, а правилата за лятно време създават невалидни или двусмислени местни часове.

Диапазонът е ограничен и местните преобразувания зависят от настройката на часовата зона на системата.

Пълната програма действително използва System.DateTime; точният очакван stdout е 2026-11-17T12:00:00.0000000Z.

Примери

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));

Резултат

2026-11-17T12:00:00.0000000Z

Пълната програма действително използва `System.DateTime`; точният очакван stdout е `2026-11-17T12:00:00.0000000Z`.

Източници