DateTimeOffset.ToUnixTimeSeconds Methode
Definition
Gibt die Anzahl der Sekunden zurück, die seit dem 1. Januar 1970 um 00:00:00Z verstrichen sind.Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.
public:
long ToUnixTimeSeconds();
public long ToUnixTimeSeconds ();
member this.ToUnixTimeSeconds : unit -> int64
Public Function ToUnixTimeSeconds () As Long
Gibt zurück
Die Anzahl der Sekunden, die seit dem 1. Januar 1970 um 00:00:00Z verstrichen sind.The number of seconds that have elapsed since 1970-01-01T00:00:00Z.
Beispiele
Im folgenden Beispiel wird die ToUnixTimeSeconds-Methode aufgerufen, um die UNIX-Zeit der Werte zurückzugeben, die gleich sind, kurz vor und kurz nach dem 1970-01-01t00:00:00Z.The following example calls the ToUnixTimeSeconds method to return the Unix time of values that are equal to, shortly before, and shortly after 1970-01-01T00:00:00Z.
using System;
public class Example
{
public static void Main()
{
DateTimeOffset dto = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds());
dto = new DateTimeOffset(1969, 12, 31, 23, 59, 0, TimeSpan.Zero);
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds());
dto = new DateTimeOffset(1970, 1, 1, 0, 1, 0, TimeSpan.Zero);
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds());
}
}
// The example displays the following output:
// 1/1/1970 12:00:00 AM +00:00 --> Unix Seconds: 0
// 12/31/1969 11:59:00 PM +00:00 --> Unix Seconds: -60
// 1/1/1970 12:01:00 AM +00:00 --> Unix Seconds: 60
Module Example
Public Sub Main()
Dim dto As DateTimeOffset = New DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds())
dto = New DateTimeOffset(1969, 12, 31, 23, 59, 0, TimeSpan.Zero)
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds())
dto = New DateTimeOffset(1970, 1, 1, 0, 1, 0, TimeSpan.Zero)
Console.WriteLine("{0} --> Unix Seconds: {1}", dto, dto.ToUnixTimeSeconds())
End Sub
End Module
' The example displays the following output:
' 1/1/1970 12:00:00 AM +00:00 --> Unix Seconds: 0
' 12/31/1969 11:59:00 PM +00:00 --> Unix Seconds: -60
' 1/1/1970 12:01:00 AM +00:00 --> Unix Seconds: 60
Hinweise
Die UNIX-Zeit gibt die Anzahl der Sekunden an, die seit 1970-01-01t00:00:00Z (1. Januar 1970, 12:00 Uhr UTC) verstrichen sind.Unix time represents the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). Es nimmt keine Schaltsekunden in Rechnung.It does not take leap seconds into account.
Diese Methode konvertiert zuerst die aktuelle Instanz in UTC, bevor die zugehörige Unix-Zeit zurückgegeben wird.This method first converts the current instance to UTC before returning its Unix time. Für Datums-und Uhrzeitwerte vor 1970-01-01t00:00:00Z gibt diese Methode einen negativen Wert zurück.For date and time values before 1970-01-01T00:00:00Z, this method returns a negative value.