RSS Feed for This PostCurrent Article

.NET: DateTime from Milliseconds

In Java, for Date we can use milliseconds to get the Date object, e.g. new Date(long milliseconds).

In .NET, there is a similar constructor, but it is accepting the number of ticks, which is new DateTime(long ticks).

In .NET, if you want to construct a DateTime object from number of milliseconds since January 1, 1970, 00:00:00 GMT, you need to use the following way

   1: DateTime dt = new DateTime((milliseconds * TimeSpan.TicksPerMillisecond) + 621355968000000000);

The value is derived from

   1: DateTime dt70 = new DateTime( 1970, 1, 1, 0, 0, 0, 0 );

   2: long ticks1970 = dt70.Ticks;

Reference:

http://www.dotnet247.com/247reference/msgs/31/156423.aspx


Trackback URL


1 Trackback(s)

  1. From .NET: DateTime from Milliseconds | Jan 23, 2011

RSS Feed for This PostPost a Comment

*