How to find difference between two dates in seconds in different timezones

calendar, date, java, time, timezone

Solution

I would use GMT everywhere and only convert to the local times for display purposes.

To find the difference, convert both times to the same timezone (say GMT) and take the difference.

Problem

I have a piece of code which finds the difference between two dates(in the format of yyyy-MM-dd hh:mm:ss) . This code is run in multiple servers across the globe. One of the two dates is the current time in that particular timezone where the code is being run(server time) and another is the time obtained from a database. if the difference between these two times is greater than 86400 seconds(1day), then it should print "invalid" else, it should print "valid". Problem im facing with the code is when I run it on my local, its working fine, but when i deploy it onto a server in US, its taking GMT time into consideration and not local time. Wherever the code is run, I want the difference between current time and time fetched from the database, and if its greater than 86400 seconds, i want to print invalid. How to achieve this in java? PS: I tried with Date object, but its considering GMT only everywhere.

Original source