java计时器

来源:互联网 发布:高中女神 体验知乎 编辑:程序博客网 时间:2024/05/21 16:59
package com.cn.love;import java.text.Format;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Timer;import java.util.TimerTask;public class time_dome {public static void main(String[] args) {//设置一个时间String str_time="2016-12-14 17:08:00";final Timer t=new Timer();Format f=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");try {Date d=(Date) f.parseObject(str_time);//转换时间格式t.schedule(new TimerTask() {@Overridepublic void run() {System.out.println("****进来了**任务执行中******");t.cancel();//停止计时器}}, d);//执行时间} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
刚学习的几录一下 后续补上几种其他的方法
0 0
原创粉丝点击