- 设置闹钟提醒
在Android 4.4 以后,为节省电池耗电等,不再使用一个重复闹钟,而是使用多个单次闹钟,当前一个闹钟到点提醒以后,再次设置下一个闹钟。
获取日历的当前时间
public Date getStartTime(String startTime){
Date startDate = DateUtil.tFormat8(startTime);
Calendar calendar=Calendar.getInstance();
calendar.setTime(startDate);
Date nowDate = DateUtil.nowDate(BaseApplication.getContext());
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTime(nowDate);
calendar.set(Calendar.YEAR, nowCalendar.get(Calendar.YEAR));
calendar.set(Calendar.MONTH, nowCalendar.get(Calendar.MONTH));
calendar.set(Calendar.DAY_OF_MONTH, nowCalendar.get(Calendar.DAY_OF_MONTH));
return calendar.getTime();
}
####判断某个日期的所属的星座
public class ConstellationUtil{
private final static int[] dayArr = new int[]{20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22};
private final static String[] constellationArr = new String[]{ “摩羯座”, “水瓶座”, “双鱼座”, “白羊座”, “金牛座”, “双子座”, “巨蟹座”, “狮子座”, “处女座”, “天秤座”, “天蝎座”, “射手座”, “摩羯座”};
public static String getConstellation(int month, int day){
return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];
}
public static getConstellation(Date date){
if(date == null)
return "";
Calendar canlendar = Calendar.getInstance();
canlendar.setTime(date);
int month = canlendar.get(Calendar.MONTH) + 1;
int day = canlendar.get(Calendar.DAY_OF_MONTH);
return getConstellation(month, day);
}
}