BastiaanJansen/otp-java

Remaining Seconds?

avkorn opened this issue · 2 comments

Hi @BastiaanJansen, is it possible somehow to get the number of seconds remaining for the TOTP?

Hi @avkorn,

You could do something like this:

TOTP totp = TOTP.withDefaultValues(secret);

long timeInterval = totp.getPeriod().toMillis();
Duration remainder = Duration.ofMillis(timeInterval - System.currentTimeMillis() % timeInterval);

System.out.println(remainder.getSeconds());

Many thanks!