ToUnixTimestamp

/// <summary>
/// Converts a System.DateTime object to Unix timestamp
/// </summary>
/// <returns>The Unix timestamp</returns>
public static long ToUnixTimestamp(this DateTime date)
{
	DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
	TimeSpan unixTimeSpan = date - unixEpoch;

	return (long)unixTimeSpan.TotalSeconds;
}
Example:
var currentUnixTimestamp = DateTime.Now.ToUnixTimestamp();

Description

Converts a System.DateTime object to Unix timestamp.

Details

Double click on the code to select all.

 

;