<p>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. </p>

<p>If you are coding a server side contract in Java use the following code:</p>

<pre><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);
}
</code></pre>

<p>If you are coding a client side app in Javascript use:  </p>

<pre><code>function fromEpochTime(epochTime) {
    return epochTime * 1000 + EPOCH_BEGINNING - 500;
};

function toEpochTime(currentTime) {
    return Math.floor((currentTime - EPOCH_BEGINNING) / 1000);
};
</code></pre>

CC BY-SA 4.0
2018-12-30T20:15:29.380Z
2018-12-30T20:15:29.380Z
lyaffe
<p>What is the best approach to convert from Ardor time to Unix time?</p>

<java><ardor><lightweight-contracts>
How to convert from Ardor time to Unix time?
almonte
# How to convert from Ardor time to Unix time?

(Asked by: username_0 on 2018-12-28)

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

**Tags:** java, ardor, lightweight-contracts


---

## 1 answers

### Answer by username_1 on 2018-12-30. Score: 3

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);
};

```


---

