带日历对象的AlarmManager Android Java [英] AlarmManager with Calendar Object Android java

查看:67
本文介绍了带日历对象的AlarmManager Android Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试制作一个简单的完全可以正常工作的闹钟,但是我一直在制作适当的闹钟...我不明白的是:

Hello im trying to make a simple fully working alarm clock but im stuck on making proper alarms... what i dont understand is this :

https://developer.android.com/training/scheduling/alarms.html

// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);

// setRepeating() lets you specify a precise custom interval--in this case,
// 20 minutes.
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        1000 * 60 * 20, alarmIntent);

  • 我们将以毫秒为单位的当前时间设置为日历,因此如果以毫秒为单位的时间将立即触发,以毫秒为单位设置当前时间然后分配小时和分钟的目的是什么?

    • we set current time in milis to the calendar so if we get time in milis it will fire right now what is the purpose of setting current time in milis and then assigning the hour and minute ?

      以毫秒为单位的设置时间可以设置从1970年到现在的毫秒数吗?

      set time in milis sets the ammount of miliseconds from the year 1970 until now ?

      以毫秒为单位的日历获取时间会返回自我们设定的小时数以来的英里数?或者 ?我完全不理解这些行,为什么我们以毫秒为单位设置当前时间,然后将小时设置为点火时间?

      calendar get time in milis returns the amount of milis since the hour we set? or ? i dont understand these lines at all, why do we set current time in millis and then set hour to fire?

      编辑-如果我将闹钟设置为在10:00及其10:05触发,该怎么办?它会立即开火........

      EDIT - if i set alarm to trigger at 10:00 and its 10:05 what should i do ? it fires imediately........

      推荐答案

      我们将日历中的当前时间设置为日历,以便在有时间的情况下 milis它会立即开火设定电流的目的是什么 时间以毫秒为单位,然后分配小时和分钟?

      we set current time in milis to the calendar so if we get time in milis it will fire right now what is the purpose of setting current time in milis and then assigning the hour and minute ?

      (严格不正确.getInstance()应该将时间自动设置为当前日期和时间-在此处以毫秒为单位设置时间可能与此无关)-目的是将当前年/月/日设置为同时.如果您仅设置小时和分钟,则在哪一天会触发并不明显.

      ( not strictly true. getInstance() should set the time to the current date and time automatically - setting the time in millis is probably irrelevant here) - The purpose is to set the current year / month / day at the same time. If you only set the hour and and minute it is not obvious on which day that will fire.

      以毫秒为单位的设置时间设置了自1970年以来的毫秒数 直到现在?

      set time in milis sets the ammount of miliseconds from the year 1970 until now ?

      自1970年1月1日起,以UTC时区为单位的当前毫秒数.

      The current number of milliseconds since January 1st 1970 in the UTC timezone.

      以毫秒为单位的日历获取时间,返回自小时以来的英里数 我们设置?或者 ?我完全不理解这些行,为什么要设置 当前时间以毫秒为单位,然后设置小时为开火时间?

      calendar get time in milis returns the amount of milis since the hour we set? or ? i dont understand these lines at all, why do we set current time in millis and then set hour to fire?

      在这种情况下,getTimeInMillis()将返回自UTC时区到1970年1月1日的毫秒数,直到今天的08:30.

      getTimeInMillis() in this case will return the number of milliseconds since January 1st 1970 in the UTC timezone, up to 08:30 of the current day.

      编辑-如果我将闹钟设置为在10:00及其10:05触发,我该怎么办 做 ?它会立即开火........

      EDIT - if i set alarm to trigger at 10:00 and its 10:05 what should i do ? it fires imediately........

      时间可能已经过去.请记住,时间在UTC!如果您在美国或亚洲,可能与您对现在"的解释大不相同.

      It is possible that the time has already passed. Bear in mind the time is in UTC! If you are in America or Asia that could be significantly different to your interpretation of "now".

      这篇关于带日历对象的AlarmManager Android Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆