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

CKTIS / C#

System.DateTimeOffset: praktická referencia

System.DateTimeOffset: praktická referencia: DateTimeOffset spája čas s posunom a tým jednoznačne určuje okamih.

Verzia: .NET API; verified on .NET 10.0.14

Syntax

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

DateTimeOffset spája čas s posunom a tým jednoznačne určuje okamih.

Použite ho pre časové pečiatky medzi systémami pri zachovaní pozorovaného posunu.

Posun nie je identifikátor časového pásma a neuchováva jeho historické pravidlá letného času.

Posun musí byť v celých minútach v rozsahu plus či mínus štrnásť hodín a výsledný UTC okamih musí byť platný.

Úplný program skutočne používa System.DateTimeOffset; presne očakávaný stdout je +01:00.

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 instant = new DateTimeOffset(2026, 11, 17, 12, 0, 0, TimeSpan.FromHours(1));
Console.WriteLine(instant.ToString("zzz", CultureInfo.InvariantCulture));

Výsledok

+01:00

Úplný program skutočne používa `System.DateTimeOffset`; presne očakávaný stdout je `+01:00`.

Zdroje