What is the best approach to convert from Ardor time to Unix time?


Ardor time is measured in seconds since the Genesis block, represented as Java int. Currently there is no API which performs conversion to Unix time so you have to code it yourself.

If you are coding a server side contract in Java use the following code:

long EPOCH_BEGINNING = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(isTestnet ? "2017-12-26 14:00:00 +0000" : "2018-01-01 00:00:00 +0000").getTime();

public static long fromEpochTime(int epochTime) {
    return epochTime * 1000L + EPOCH_BEGINNING - 500L;

public static int toEpochTime(long currentTime) {
    return (int)((currentTime - EPOCH_BEGINNING + 500) / 1000);

If you are coding a client side app in Javascript use:

function fromEpochTime(epochTime) {
    return epochTime * 1000 + EPOCH_BEGINNING - 500;

function toEpochTime(currentTime) {
    return Math.floor((currentTime - EPOCH_BEGINNING) / 1000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.