Chinaunix首页 | 论坛 | 博客
  • 博客访问: 102913
  • 博文数量: 60
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-09 12:19
文章分类

全部博文(60)

文章存档

2015年(3)

2014年(41)

2013年(16)

我的朋友

分类: Java

2014-05-10 21:01:11

package com.test;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;


public class MainTest {


 public static void main(String[] args)  {
  
  Timer timer=new Timer();
  MyTimerTask task=new MyTimerTask();
  timer.schedule(task, new Date(), 1000);
 }
}


class MyTimerTask extends java.util.TimerTask { 
 String now; 
 public void run() {
  
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  now=sdf.format(new Date());
  System.out.println(now);
  
 }
 
 public String getNow(){
  return this.now;
 }
  
}
阅读(278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~