安卓:减去分钟,我的闹钟 [英] Android: Subtract minutes to my alarm
问题描述
我做的警报,获取当前时间如下:
I'm making an alarm, get the current time as follows:
public String getAlarmTimeStringFive2db() {
String timef2db = "";
if (alarmTime.get(Calendar.HOUR_OF_DAY) <= 9)
timef2db += "0";
timef2db += String.valueOf(alarmTime.get(Calendar.HOUR_OF_DAY));
timef2db += ":";
if (alarmTime.get(Calendar.MINUTE) <= 9)
timef2db += "0";
timef2db += String.valueOf(alarmTime.get(Calendar.MINUTE));
return timef2db;
}
...
public static long create(Alarm alarm) {
ContentValues cv = new ContentValues();
cv.put(COLUMN_ALARM_ACTIVE, alarm.getAlarmActive());
cv.put(COLUMN_ALARM_TIME, alarm.getAlarmTimeStringFive2db());
...
public void setAlarmTime(String alarmTime) {
String[] timePieces = alarmTime.split(":");
Calendar newAlarmTime = Calendar.getInstance();
newAlarmTime.set(Calendar.HOUR_OF_DAY,
Integer.parseInt(timePieces[0]));
newAlarmTime.set(Calendar.MINUTE, Integer.parseInt(timePieces[1]));
newAlarmTime.set(Calendar.SECOND, 0);
setAlarmTime(newAlarmTime);
}
...
这工作得很好,例如返回5:35 ......没事了。
This works fine, for example returns 5:35 ... all right.
我的问题是我想在时间总是减去5分钟。如果时间是5:35,我要报警时间开始于5:30。
My problem is I want to subtract 5 minutes always on time. If the time is 5:35, I want the alarm time starts at 5:30.
我的问题是我不知道该怎么减的5分钟。
我试过
My problem is I do not know how to subtract those 5 minutes. I tried
Calendar.MINUTE,的Integer.parseInt(钟表[1],5)
Calendar.MINUTE, Integer.parseInt(timePieces[1],5)
Calendar.MINUTE,-5)
Calendar.MINUTE, -5)
...但没有任何工程
...but nothing works
我看了这个链接
<一href=\"http://stackoverflow.com/questions/11857251/set-alarm-to-alert-5-minutes-before-a-certian-time\">Set报警,以提醒5分钟certian时间之前
..但我不能把它应用到我的code
I read this link Set Alarm To Alert 5 Minutes Before a certian Time .. but I could not apply it to my code
谁能告诉我,我减去报警5分钟?
Can anyone tell me as subtracting 5 minutes of my alarm?
在此先感谢
问候
推荐答案
我不知道,如果你正在使用正确的方式日历实例,但这里有一个例子显示了当使用添加时间变化-5到当前日历
I'm not sure if you are using the Calendar instance in the right way, but here is an example shows that time changes when use add -5 to the current calendar
Calendar cal = Calendar.getInstance();
System.out.println("Before :" + cal.get(Calendar.MINUTE));
cal.add(Calendar.MINUTE, -5);
System.out.println("After :" + cal.get(Calendar.MINUTE));
和结果会是这样的:
Before :37
After :32
这篇关于安卓:减去分钟,我的闹钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!