DateTimeExtensionsToUnixSeconds Method

Gets the time elapsed since the Unix Epoch time (1970-01-01T00:00Z) in seconds, not counting leap seconds.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static long ToUnixSeconds(
	this DateTime value
)

Parameters

value  DateTime
A DateTime value to get the Unix time from.

Return Value

Int64
The number of seconds that have elapsed since 1970-01-01T00:00Z.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DateTime. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method is similar to DateTimeOffset.ToUnixTimeSeconds but is available even below .NET Framework 4.6.

If value is a Local time, then its Kind is converted to UTC first.

This method returns a negative value for times before 1970-01-01T00:00Z.

See Also