How do I convert transaction timestamp to datetime? It seems it isn’t unix or java time stamp.
hello there,
NEM uses a timestamp starting from the so-called NEM Epoch, using Javascript you can use this:
var nemTime = metaDataPair.transaction.timeStamp;
var nemEpoch = Date.UTC(2015, 2, 29, 0, 6, 25, 0);
return new Date(nemEpoch + (nemTime * 1000));
Cheers
2015-2-29 doesn’t exist. I use the transaction date time and look at the time stamp and treat it as seconds, not milliseconds and the epoch date comes out to be around 2015-3-28. Am I messing up something?
Thanks to your providing the name nemEpoch I was able to find my answer here https://github.com/NemProject/nembex-v3/blob/master/nemUpdate.py
the Date function works with indexed number of months… so it means 2015-03-29
Wrote a few lines of code in Python to convert datetime to Unix Time and finally to NEM Epoch.
For example, this allow you to figure out, given a latest block’s generation time, what is its NEM epoch time.
https://repl.it/repls/SmoggyMiserlyFiles
##
# Conversion of datetime to unix time and to NEM relative time
# https://forum.nem.io/t/about-nem-nemesis-time/16729
#
import datetime
import time
# Nemesis time, i.e. generation of first block
nemEpoch=datetime.datetime(2015, 3, 29, 0, 6, 25, 0, None)
print("NEM Nemesis Date:",nemEpoch)
unixtime = time.mktime(nemEpoch.timetuple())
print ("NEM Nemesis enesis Unix Time:",int(unixtime))
print("--------------------------------")
# date of interest, e.g. a block's generation time
date1 = datetime.datetime(2018,12,27,1,6,31)
unixtime1=time.mktime(date1.timetuple())
print("Block Generation Time:", date1)
print("Block Generation Unix Time:",int(unixtime1))
timestamp_nem=unixtime1-unixtime
print ("--------------------------------")
print("Block NEM Time:",int(timestamp_nem))
One can use this in C#,
DateTime startDateTime = new DateTime(2015, 03, 29, 05, 36, 25); //timestamp of 1st block
long timeStampInTicks = (long)(timeStamp * TimeSpan.TicksPerSecond);
return new DateTime(startDateTime.Ticks + timeStampInTicks);