Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find number of days between two unix timestamps in java

Tags:

java

timestamp

I am using unix timestamp to store the purchase date in my application. sample data: 1371463066

I want to do some manipulation based on the difference in number of days and current day timestamp. for example: If the number of days between the purchase date and current date is 5 days, then send an email regarding feedback again.

how to get the difference in days between two timestamps using java?

like image 878
Poppy Avatar asked Jun 17 '13 09:06

Poppy


1 Answers

I have not tested it but you may try to do something like this:

Date purchasedDate = new Date ();
//multiply the timestampt with 1000 as java expects the time in milliseconds
purchasedDate.setTime((long)purchasedtime*1000);

Date currentDate = new Date ();
currentDate .setTime((long)currentTime*1000);

//To calculate the days difference between two dates 
int diffInDays = (int)( (currentDate.getTime() - purchasedDate.getTime()) 
                 / (1000 * 60 * 60 * 24) )
like image 64
Juned Ahsan Avatar answered Oct 13 '22 01:10

Juned Ahsan