2

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

2

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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