0

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;
    }
}
 }
user1502224
  • 95
  • 2
  • 13

1 Answers1

0

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 Calendar class (see docs) to extract info about current time. Here's an example code that assumes, you want to use default Locale and TimeZone, if that's not the case please refer to other Calendar.getInstance() methods.

// Get Calendar object with current date and time (assumes default Locale and TimeZone).
Calendar calendar = Calendar.getInstance()

// Retrieve info about current time.
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);

// Compare with values selected in TimePicker
if (tp.getCurrentHour().intValue() == hour) { // similar applies to 'minute'
    // do whatever you want
}
vArDo
  • 4,408
  • 1
  • 17
  • 26