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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With