0

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

AndroidDev
  • 888
  • 3
  • 13
  • 27
  • 1
    A Unix timestamp — also the one in your link — is in seconds, not milliseconds since the Unix epoch. So you probably want `Instant.now().toEpochSecond()`rather than `toEpochMilli()`. – Ole V.V. Aug 13 '21 at 15:35

1 Answers1

1

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.

Chris
  • 4,662
  • 2
  • 19
  • 27