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
  • 909
  • 10
  • 25
Mohit H
  • 927
  • 3
  • 11
  • 26

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
  • 257,207
  • 101
  • 511
  • 656
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,408
  • 1
  • 15
  • 26