zoukankan      html  css  js  c++  java
  • 指定某时间段运行某个需求

    在近期的项目中有个需求就是在用户选择了代抢位的时间段没有抢到车位就给用户一个友好的提示,比方用户选择的是

    2014-10-08:18:00这个时间,那么到了这个时间假设用户没有枪到车位就弹出一个对话框告诉用户,让用户做其它选择,

    在android中一般有2中做法,一种是使用闹钟,也就是AlarManger,另一种是Timer(定时器)


    在此项目中就使用另外一种方法实现

    新建一个java项目 TimerDemo

    public class TimerDemo {
    	public static void main(String[] args) {
    		Timer timer = new Timer();
    		DateTask task = new DateTask();
    		  String current = "2014-10-8 11:39";
    	        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    	        Date date  = null;
    	        try {
    	            date  = simpleDateFormat.parse(current);
    	        } catch (ParseException e) {
    	            e.printStackTrace();
    	        }
    		timer.schedule(task, date);
    	}
    	static class DateTask extends TimerTask{
    		@Override
    		public void run() {
    			System.out.println("时间到了");	
    		}
    	}
    }

    Timer还有非常多重载的方法

    如图:

    在此记录下

  • 相关阅读:
    java 整型相除得到浮点型
    Interleaving String
    Insert Interval
    Mashup
    R-TREE
    默认以管理员身份运行VS2013/15/17
    C:malloc/calloc/realloc/alloca内存分配函数
    VS2015快捷键
    C++:UNREFERENCED_PARAMETER用法
    VC++常用数据类型及其操作详解
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6755984.html
Copyright © 2011-2022 走看看