How to check if the timestamp is current date's timestamp

java, timestamp, unix-timestamp

Solution

The epoch you posted is in seconds. Java uses milliseconds so you have to convert it and then compare the two.

long epochInMillis = epoch * 1000;
Calendar now = Calendar.getInstance();
Calendar timeToCheck = Calendar.getInstance();
timeToCheck.setTimeInMillis(epochInMillis);

if(now.get(Calendar.YEAR) == timeToCheck.get(Calendar.YEAR)) {
    if(now.get(Calendar.DAY_OF_YEAR) == timeToCheck.get(Calendar.DAY_OF_YEAR)) {
    }
}

You can also change the time zone if you do not want to use the default, in case the input epoch is in a different time zone.

Problem

I have a scheduler that needs to check if the incoming timestamp is current day's timestamp. The incoming timestamp will be of the format Eg:1384956395. How to check this in java? Please help. I am not using Joda

Original source

Related problems