private static Timer timer = new Timer();
static public class MyTask extends TimerTask
{
public void run()
{
System.out.println("运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTask task = new MyTask();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2015-10-6 12:14:00";
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(task, dateRef);
}
字符串时间:2015-10-6 12:14:00 当前时间:2015-10-6 12:13:23 运行了!时间为:Tue Oct 06 12:14:00 CST 2015
public Timer() {
this("Timer-" + serialNumber());
}
public Timer(String name) {
thread.setName(name);
thread.start();
}
public Timer(boolean isDaemon) {
this("Timer-" + serialNumber(), isDaemon);
}
public Timer(String name, boolean isDaemon) {
thread.setName(name);
thread.setDaemon(isDaemon);
thread.start();
}
private static Timer timer = new Timer();
static public class MyTask extends TimerTask
{
public void run()
{
System.out.println("运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTask task = new MyTask();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2014-10-6 12:14:00";
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(task, dateRef);
}
字符串时间:2014-10-6 12:14:00 当前时间:2015-10-6 12:20:10 运行了!时间为:Tue Oct 06 12:20:10 CST 2015
private static Timer timer = new Timer();
static public class MyTask extends TimerTask
{
public void run()
{
System.out.println("运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTask task1 = new MyTask();
MyTask task2 = new MyTask();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString1 = "2015-10-6 12:26:00";
String dateString2 = "2015-10-6 12:27:00";
Date dateRef1 = sdf1.parse(dateString1);
Date dateRef2 = sdf2.parse(dateString2);
System.out.println("字符串时间:" + dateRef1.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
System.out.println("字符串时间:" + dateRef2.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(task1, dateRef1);
timer.schedule(task2, dateRef2);
}
static public class MyTask extends TimerTask
{
public void run()
{
System.out.println("运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTask task = new MyTask();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2015-10-6 18:00:00";
Timer timer = new Timer();
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(task, dateRef, 4000);
}
static public class MyTask extends TimerTask
{
public void run()
{
System.out.println("运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTask task = new MyTask();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2014-10-6 18:01:00";
Timer timer = new Timer();
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(task, dateRef, 4000);
}
static public class MyTaskA extends TimerTask
{
public void run()
{
System.out.println("A运行了!时间为:" + new Date());
this.cancel();
}
}
static public class MyTaskB extends TimerTask
{
public void run()
{
System.out.println("B运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTaskA taskA = new MyTaskA();
MyTaskB taskB = new MyTaskB();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2015-10-6 18:10:00";
Timer timer = new Timer();
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(taskA, dateRef, 4000);
timer.schedule(taskB, dateRef, 4000);
}
字符串时间:2015-10-6 18:10:00 当前时间:2015-10-6 18:09:47 A运行了!时间为:Tue Oct 06 18:10:00 CST 2015 B运行了!时间为:Tue Oct 06 18:10:00 CST 2015 B运行了!时间为:Tue Oct 06 18:10:04 CST 2015 B运行了!时间为:Tue Oct 06 18:10:08 CST 2015 B运行了!时间为:Tue Oct 06 18:10:12 CST 2015 ...
private static Timer timer = new Timer();
static public class MyTaskA extends TimerTask
{
public void run()
{
System.out.println("A运行了!时间为:" + new Date());
timer.cancel();
}
}
static public class MyTaskB extends TimerTask
{
public void run()
{
System.out.println("B运行了!时间为:" + new Date());
}
}
public static void main(String[] args) throws Exception
{
MyTaskA taskA = new MyTaskA();
MyTaskB taskB = new MyTaskB();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = "2015-10-6 18:10:00";
Date dateRef = sdf.parse(dateString);
System.out.println("字符串时间:" + dateRef.toLocaleString() + " 当前时间:" + new Date().toLocaleString());
timer.schedule(taskA, dateRef, 4000);
timer.schedule(taskB, dateRef, 4000);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有