public void addTimer() { long timeOn = mTimeOnDate.getTime(); // time in milliseconds long timeOff = mTimeOffDate.getTime(); // time in milliseconds long duration = timeOff - timeOn; if (duration < 0) { duration += 86400000; // milliseconds per day } long now = new Date().getTime(); long timeFromNow = timeOn - now; if (timeFromNow < 0) { timeFromNow += 86400000; } String url = "http://" + mHardwareUnit.getBasePath() + ":" + mHardwareUnit.getPortNumber() + "/hack/setTimer?socket=" + mDevice.getSocketId() + "&timeFromNow=" + timeFromNow + "&duration=" + duration + "&isRepeated=" + mIsRepeatedCheckBox.isChecked(); HackCommand setTimerCommand = new HackCommand(SetTimerActivity.this, mHardwareUnit, url) { @Override public void doSuccess(JSONObject response) { super.doSuccess(response); long timerId = mTimerDataSource.addTimer( mDeviceId, mTimeOnDate.getTime(), mTimeOffDate.getTime(), mIsRepeatedCheckBox.isChecked()); startDeviceDetailsActivity(); } }; setTimerCommand.send(); }