static void setTime(Context context, int hourOfDay, int minute) {Calendar c = Calendar.getInstance();c.set(Calendar.HOUR_OF_DAY, hourOfDay);c.set(Calendar.MINUTE, minute);c.set(Calendar.SECOND, 0);c.set(Calendar.MILLISECOND, 0);long when = c.getTimeInMillis();if (when / 1000 < Integer.MAX_VALUE) {((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when);}}
static void setDate(Context context, int year, int month, int day) {Calendar c = Calendar.getInstance();c.set(Calendar.YEAR, year);c.set(Calendar.MONTH, month);c.set(Calendar.DAY_OF_MONTH, day);long when = c.getTimeInMillis();if (when / 1000 < Integer.MAX_VALUE) {((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when);}}
<uses-permission android:name="android.permission.SET_TIME" />
原文:http://www.cnblogs.com/Michelangelo/p/4710114.html