导航

Convert Time to UNIX Time in C#

Posted on 2005-03-27 22:46  色彩与空间  阅读(1170)  评论(0编辑  收藏  举报
I needed to convert now (datetime) to UNIX Time (number of seconds or milliseconds since jan 1, 1970) using C#.

I was able to use this little code to do the conversion.

DateTime dt70 = new DateTime( 1970110000 );
long ticks1970 = dt70.Ticks;
int gmt = (int) ((DateTime.UtcNow.Ticks - ticks1970 ) / 10000000L);