Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

System.DateTimeOffset: praktická reference

System.DateTimeOffset: praktická reference: DateTimeOffset spojuje čas s posunem a tím jednoznačně určuje okamžik.

Verze: .NET API; verified on .NET 10.0.14

Syntaxe

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

DateTimeOffset spojuje čas s posunem a tím jednoznačně určuje okamžik.

Použijte jej pro časová razítka mezi systémy při zachování pozorovaného posunu.

Posun není identifikátor časového pásma a neuchovává jeho historická pravidla letního času.

Posun musí být v celých minutách v rozsahu plus či minus čtrnáct hodin a výsledný UTC okamžik musí být platný.

Úplný program skutečně používá System.DateTimeOffset; přesně očekávaný stdout je +01:00.

Pří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ýsledek

+01:00

Úplný program skutečně používá `System.DateTimeOffset`; přesně očekávaný stdout je `+01:00`.

Zdroje