AngularJS定时执行任务
1、在控制器中注入 interval
在 controller 中 引入 $interval 【类比$http ,$scope】
2、var time = $interval(X,Y,[Z])
x: 需要执行的代码
y:指定执行的时间间隔
z:指定代码执行的次数 ,如果不指定,这无限执行下去
3、$interval.cancel(time);
关闭 定时任务
如何计算时间差
1、先获取数据库中关于日期的 数据
2、在根据数据库的数据个将数据进行解析【获取日历数据对应的毫秒值】
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date fromDate1 = simpleFormat.parse("2018-03-01 12:00");
Date toDate1 = simpleFormat.parse("2018-03-12 12:00");
long from1 = fromDate1.getTime();
long to1 = toDate1.getTime();
3、计算出 日期数据之间的毫秒差值
// 计算 天数差
int days = (int) ((to1 - from1) / (1000 * 60 * 60 * 24));
// 计算小时差
int hours = (int) ((to2 - from2) / (1000 * 60 * 60));
// 计算分钟差
int minutes = (int) ((to3 - from3) / (1000 * 60));