« VMWare Server (beta) licence | Each process his own virtual environment? »
Convert C# DateTime to unix timestamp
By Lennard | April 3, 2006
-
DateTime now = new DateTime(2006, 3, 22, 23, 12, 23);
-
TimeSpan t = (now - new DateTime(1970, 1, 1).toLocalTime());
-
int timestamp = (int) t.TotalSeconds;
Topics: c# | 5 Comments »
April 5th, 2008 at 13:32
Thanks for posting this – it’s exactly what I was looking for!
September 3rd, 2008 at 16:59
What is “toLocalTime” ???
October 22nd, 2008 at 07:34
It should be ToLocalTime (capitalized “to”)
May 15th, 2010 at 02:01
Is better if you use ToUniversalTime to convert
March 2nd, 2011 at 17:29
For GMT TIME use :
int timestamp = (int)(DateTime.UtcNow – new DateTime(1970, 1, 1)).TotalSeconds;
Works for me