-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimerTest.java
More file actions
50 lines (41 loc) · 1.22 KB
/
Copy pathTimerTest.java
File metadata and controls
50 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package java_base;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
class MyTask extends TimerTask{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("����");
}
}
public class TimerTest{
public static void main(String[] args)throws Exception {
// String datetime = "2018-04-26 14:33:00";
//
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//
// Date date = sdf.parse(datetime);
//
// System.out.println(date);
System.out.println("hello");
Timer timer = new Timer();
// timer.schedule(new MyTask(), 1000, 2000);
String datetime = "2018-05-09 17:45:00";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = sdf.parse(datetime);
timer.schedule(new MyTask(), date);
Thread.sleep(50000);
timer.cancel();
}
}
/*
* дһ����ʱ���� ��дrun���� class MyTask extends TimerTask
* ����һ����ʱ��ʵ�� new Timer
* ��ʼ���ö�ʱ���� ����һֱִ�г��� timer.cancel()�� timer.schedule(xxxx)
*
*
* �߳���ʱ Thread.sleep(50000) ms ��ʱ50s
*
*/