Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

dates and time: praktická referencia

dates and time: praktická referencia: Čas rozlišuje okamih, miestny dátum, zónu, posun a trvanie.

Verzia: C# language and .NET 10 reference runtime

Syntax

// time

Čas rozlišuje okamih, miestny dátum, zónu, posun a trvanie.

Okamihy ukladajte v UTC alebo DateTimeOffset a zónu držte ako samostatné obchodné pravidlo.

Nástenné hodiny sa môžu vrátiť; na intervaly použite monotónny Stopwatch alebo TimeProvider.

DST vytvára neexistujúce a nejednoznačné časy a rozsahy typov sú obmedzené.

Úplný program skutočne používa dates and time; presne očakávaný stdout je 2026-11-18.

Príklady

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.AddDays(1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));

Výsledok

2026-11-18

Úplný program skutočne používa `dates and time`; presne očakávaný stdout je `2026-11-18`.

Zdroje