0

i am beginner in java and i wan't to substract to date in java and i wan't diffrence between to date in days.

so for that i have using below approch to solve this

long diff = Math.abs(d1.getTime() - d2.getTime());

long diffDays = diff / (24 * 60 * 60 * 1000);

But this will fail across spring's daylight savings boundary.

Example d1 = new Date(112, 3-1, 11, 0, 0, 0), d2 = new Date(112, 3-1, 12, 0, 0, 0), results in 0.

so please help me to solve this problem. i have also referred Subtract two dates in Java but not getting excat answer that i wan't.

thank you.

Community
  • 1
  • 1
KARAN
  • 1,023
  • 1
  • 12
  • 24
  • @tunaki this is not duplicate question i wan't solution for day light saving time – KARAN May 31 '16 at 12:29
  • There are answers properly taking DST into account, like http://stackoverflow.com/questions/1555262/calculating-the-difference-between-two-java-date-instances/23184523#23184523 – Tunaki May 31 '16 at 12:30
  • you are giving link that not provide good solution for EST @Tunaki – KARAN May 31 '16 at 12:32
  • so pls understand my problem that not given any good suggestion for est and i beginner in java@Tunaki – KARAN May 31 '16 at 12:33
  • This not Duplicate question no one can provide solution for est and if you able to understand this question as duplicate then provide solution in comment @Tunaki – KARAN May 31 '16 at 12:34
  • The solution given work for all timezones, including EST. You need to read them properly, and refer to the documentation. – Tunaki May 31 '16 at 12:35

0 Answers0