So what I am trying to do is to make an alarm clock. I am having trouble getting the current time and get the timepicker’s time to compare them. If you could help me out a bit just getting the timepicker’s time and the current time in the same kind of measurement would be great.
Thanks a ton =)
Here is my code:
public class AlarmlockActivity extends Activity implements OnClickListener {
TimePicker tp;
Button set;
long currentTime;
long alarmTime;
long alarmHourmil;
DigitalClock dc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tp = (TimePicker) findViewById(R.id.tpAlarmTime);
set = (Button) findViewById(R.id.bSet);
dc = (DigitalClock) findViewById(R.id.digitalClock1);
currentTime = System.currentTimeMillis();
set.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()){
case R.id.bSet:
break;
}
}
}
I assume that extracting hour and minutes from current time is enough to get “timepicker’s time and the current time in the same kind of measurement.
If that’s the case you can use
Calendarclass (see docs) to extract info about current time. Here’s an example code that assumes, you want to use defaultLocaleandTimeZone, if that’s not the case please refer to otherCalendar.getInstance()methods.