How to convert assetTimeStamp to DateTime?

Hi Guys.

What I want is comparing two asset’s timestamp and if their difference is bigger than threshold, reprace A and B.

I cound get the timestamp like this.
AssetImporter.GetAtPath(“path”).assetTimeStamp

But it was not type of DateTime, so I can’t determine threshold…

How to convert assetTimeStamp to DateTime?

assetTimeStamp is of type ulong (unsigned long). It probably represents the in nanoseconds or ticks or something like that. If we take the example(and implementation) of nano seconds conversation from this stack overflow post, you get:

David Martin’s implementation from SO:

static DateTime GetDTCTime(ulong nanoseconds, ulong ticksPerNanosecond)
{
    DateTime pointOfReference = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    long ticks = (long)(nanoseconds / ticksPerNanosecond);
    return pointOfReference.AddTicks(ticks);
}

static DateTime GetDTCTime(ulong nanoseconds)
{
    return GetDTCTime(nanoseconds, 100);
}

This gives a date time of: 01 March 2003 14:34:50 using the following call:

ulong timeN = 99844490909448899;//time in nanoseconds
DateTime theDate = GetDTCTime(timeN);

In case anyone stumbles on this post while searching for a correct solution:


DateTime AssetTimeStampToDate(ulong assetTimeStamp)
{
    DateTime time = new DateTime((long)assetTimeStamp);
    DateTime localTime = time.ToLocalTime();
    return localTime;
}