Search code examples
androidkotlinunix-timestampepoch

How to convert epoch timestamp to unix hex timestamp in kotlin?


I am using the following code to get the current epoch time in kotlin.

val epochTime = Instant.now().toEpochMilli()

Output: 1628769521313

And now the question is how can I convert this timestamp to Unix hex timestamp (https://www.epochconverter.com/hex)

Thank you in advance


Solution

  • All that is required as far as I can see is that the decimal epoch output needs to be converted into a hexidecimal string.

    This can be achieved simply by

    "%X".format(1628769521313).

    this was taken from this answer. You can see many other ways of doing the same thing in that question too.