views:

462

answers:

2

I want to convert a number that is in PRTime format (a 64-bit integer representing the number of microseconds since midnight (00:00:00) 1 January 1970 Coordinated Universal Time (UTC)) to a datetime.

note that this is slightly different than the usual "number of millisecconds since 1/1/1970"

+1  A: 
Dim prTimeInMillis as UInt64
prTimeInMillis = prTime/1000

dim prDateTime as new DateTime(1970, 1, 1)
prDateTime = prDateTime.AddMilliseconds(prTimeInMillis)
Barry
i had to changeprDateTime.AddMilliseconds(prTimeInMillis)toprDateTime = prDateTime.AddMilliseconds(prTimeInMillis)to get the correct value
vitorsilva
I was just shooting from memory there, glad it was helpful.
Barry
A: 

DateTime has a constructor that takes Ticks (which are 100nanoseconds).

So take your prTime multiply it by 10 and add it to the number of ticks representing the Epoch time and you have your conversion.

private static DateTime epoch = new DateTime(1970, 1, 1);
private static DateTime ConvertPrTime(long time)
{
    return new DateTime(epoch.Ticks + (time*10), DateTimeKind.Utc);
}