本帖最后由 采集的小蜜蜂 于 2021-1-15 16:34 编辑
他为什么要创建两个Calendar的实例?c.set(Calendar.HOUR, hourOfDay);这个方法是左边付给右边,还是右边赋值给左边?[Java] 纯文本查看 复制代码 case R.id.btn_set:
Calendar currentTime = Calendar.getInstance();
new TimePickerDialog(MainActivity.this, 0,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
//设置当前时间
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
// 根据用户选择的时间来设置Calendar对象
c.set(Calendar.HOUR, hourOfDay);
c.set(Calendar.MINUTE, minute);
// ②设置AlarmManager在Calendar对应的时间启动Activity
alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi);
Log.e("HEHE",c.getTimeInMillis()+""); //这里的时间是一个unix时间戳
// 提示闹钟设置完毕:
Toast.makeText(MainActivity.this, "闹钟设置完毕~"+ c.getTimeInMillis(),
Toast.LENGTH_SHORT).show();
}
}, currentTime.get(Calendar.HOUR_OF_DAY), currentTime
.get(Calendar.MINUTE), false).show();
btn_cancel.setVisibility(View.VISIBLE);
break; |