0

i am trying to find number of days from todays date from the below epoch timestamp:-

1560593315387

like this :

System.out.println(ChronoUnit.DAYS.between(Instant.ofEpochSecond(1558353632),Instant.now()));

It is working fine for 1558353632 but for 1560593315387 it cannot convert and not giving expected results.

Onkar Musale
  • 859
  • 11
  • 23
Mohit H
  • 813
  • 3
  • 11
  • 22

2 Answers2

2

1560593315387 looks to be milliseconds, not seconds, so use Instant.ofEpochMilli.

It is also too long (hah!) to fit into an int, so you have to use a long literal instead (with an L at the end).

 ChronoUnit.DAYS.between(Instant.ofEpochMilli(1560593315387L), Instant.now())
Thilo
  • 250,062
  • 96
  • 490
  • 643
0

Please do

    int seconds = (int) 1560593315387l / 1000;// (millisecond to senconds conversion)

    System.out.println(ChronoUnit.DAYS.between(Instant.ofEpochSecond(seconds), Instant.now()));
RAJKUMAR NAGARETHINAM
  • 1,140
  • 11
  • 26