Skip to content

Principia Programatica: Greg Miller's Blog

Just Programming

Recent Posts

  • A Simple Markov Chain Text Generator Example Implementation
  • Setting Manual Exposure in OpenCV
  • Android: Simple Example of Page Transition Using ViewPager
  • A Quick Snippet for Drawing Images in Java
  • A basic 3d to 2d projection

Recent Comments

  • java – Is System.nanoTime() completely useless?-ThrowExceptions – ThrowExceptions on Beware of System.nanoTime() in Java

Archives

  • October 2020
  • June 2017
  • May 2015
  • October 2014
  • September 2014
  • August 2014
  • July 2013
  • September 2012
  • July 2011
  • June 2011
  • August 2010
  • August 2009
  • June 2009
  • October 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • November 2007
  • October 2007
  • September 2007
  • May 2007
  • March 2007
  • January 2007
  • December 2006
  • October 2006

Categories

  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Month: January 2007

Get the Unix Epoch time in one line of C#

int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;

An alternate (possibly faster) method might be:

long time = (DateTime.UtcNow.Ticks - 621355968000000000) / 10000000;

Although the second method does conform to the Unmaintainable Code standard, I’d recommend sticking with the first method unless you really need those extra nanoseconds.

Posted on January 3, 2007Leave a comment on Get the Unix Epoch time in one line of C#
Proudly powered by WordPress