从用户输入(numberpicker)添加闹钟时间。
像1小时一样,0分钟设置为当前时间增加到下午1点53分,下午2点53分
然后它说"闹钟现在设定为13小时" ,并添加警报。
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
c.add(Calendar.HOUR_OF_DAY, hrs.getValue());
c.add(Calendar.MINUTE, mins.getValue());
Calendar opt = c;
SimpleDateFormat time = new SimpleDateFormat("hh:mm");
String timeformat = time.format(opt.getTime());
String splitTime[] = timeformat.split(":");
int hour = Integer.parseInt(splitTime[0]);
int minute = Integer.parseInt(splitTime[1]);
op.setText("OP:" + timeformat);
Intent s = new Intent (AlarmClock.ACTION_SET_ALARM);
s.putExtra(AlarmClock.EXTRA_MINUTES, minute);
s.putExtra(AlarmClock.EXTRA_HOUR, hour);
s.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
s.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(s);
}
但正确的人应该说"警报是从现在起1小时后设定的" ..不知道为什么它会像这样......
任何人都帮助我..
答案 0 :(得分:0)
这可能不是您所寻找的答案,因为我不熟悉Android。但是,我有一个理论,即时间以24小时格式存储。您可能认为时间设置为下午2点(14:00),但实际上是凌晨2点(02:00)。其中您没有为PM时间变化添加12小时。