I'm trting to send data every 10 seconds , so I'm trying tp use this code I wrote but I think I made a mistake in the converting to seconds?
Calendar Time= Calendar.getInstance(); Calendar SendDate= Calendar.getInstance(); long upload = TimeBetweenDates(SendTime,Time); if (upload > 10000) { String udp = "OK"; SendUDP(udp); SendTime = Calendar.getInstance(); } public static long TimeBetweenDates (Calendar Start , Calendar End) { long end = End.getTimeInMillis(); long start = Start.getTimeInMillis(); return TimeUnit.MILLISECONDS.toSeconds(Math.abs(end - start)); }
ScheduledExecutorfor sending so you don't have to calculate a difference at all?TimeBetweenDatesmethod seems like it should be correct except that in Java method and variable names begin with a lowercase letter. I find it confusing that you have parametersStartandEndand variablesstartandend. In what way does your observed behaviour differ from the desired?