PHP timestamp (int) comparison with java timestamp (long)
I hit a brick wall.
I am downloading encrypted tier data from the server (created by the tier creator I created).
Layer data stores the latest updated version of data with long Java usage.
Now, to update the levels, I load the list of available levels since they were last modified in the file using php.
Many would say that I would need to store the time elsewhere, like json. This is not an option.
I get the following results:
Fri May 08 23:05:24 CEST 2015 | timeStampJava: 1431119124273
Sat Jan 17 14:31:58 CET 1970 | fileTimeStampPHP(filemtime): 1431118989
OLLY:LOG: ---
Fri May 08 23:05:28 CEST 2015 | timeStampJava: 1431119128871
Sat Jan 17 14:31:58 CET 1970 | fileTimeStampPHP(filemtime): 1431118989
OLLY:LOG: ---
Fri May 08 23:05:32 CEST 2015 | timeStampJava: 1431119132288
Sat Jan 17 14:31:58 CET 1970 | fileTimeStampPHP(filemtime): 1431118989
OLLY:LOG: ---
Fri May 08 23:05:35 CEST 2015 | timeStampJava: 1431119135289
Sat Jan 17 14:31:58 CET 1970 | fileTimeStampPHP(filemtime): 1431118989
OLLY:LOG: ---
Fri May 08 23:05:38 CEST 2015 | timeStampJava: 1431119138807
Sat Jan 17 14:31:58 CET 1970 | fileTimeStampPHP(filemtime): 1431118989
I am trying to compare the two using:
if(serverLevelInfo.last_updated > localLevelStorage.getLastUpdated())
The problem is I am omitting the ie
phpTimeStamp > (int)javaTimeStamp
It produces completely inaccurate results.
What he is doing now?
Edit 1
Attempt:
//TODO Problem PHP int timestamp to java long timestamp.
PolyUtils.log((long)(serverLevelInfo.last_updated * 1000));
PolyUtils.log(localLevelStorage.getLastUpdated());
PolyUtils.log("---");
Result (wrong)
OLLY:LOG: 894879432
OLLY:LOG: 1431119124273
OLLY:LOG: ---
OLLY:LOG: 894879432
OLLY:LOG: 1431119128871
OLLY:LOG: ---
OLLY:LOG: 896347432
OLLY:LOG: 1431119132288
OLLY:LOG: ---
OLLY:LOG: 894879432
OLLY:LOG: 1431119135289
OLLY:LOG: ---
OLLY:LOG: 894879432
OLLY:LOG: 1431119138807
OLLY:LOG: ---
Unfortunately, the only solution is that you have to lose some precision in JAVA for a long time. This is because PHP cannot create longs (32-bit scalar vars.)
if(serverLevelInfo.last_updated > (int)(localLevelStorage.getLastUpdated() / 1000))
Make sure you select int AFTER you have separated the length, otherwise you will be inaccuracies.
You need to multiply unix timestamp (php) by 1000 because java is expecting milliseconds.
java.util.Date time=new java.util.Date((long)timeStamp*1000);