每秒钟显示当前日期和时间

时间:2019-03-24 05:00:21

标签: java jsp servlets

我想在我的JSP页面上每秒钟打印当前日期和时间,TimerTask类的run()仅返回void。我如何从此类返回当前时间,请任何Java Geeks帮助我解决这个问题

public  class ITCBillDeskRetrieveTrialDDHHMMSS extends TimerTask
{

    Logger 
         logger=Logger.getLogger(ITCBillDeskRetrieveTrialDDHHMMSS.class);
    public static String retrieveTraialDate;

    @Override
    public void run() 
    {
        try 
        {
            retrieveTraialDate();
        } 
        catch (ParseException | IOException e)
        {
            e.printStackTrace();
        }
    }

    //print Current & Print Date //
    public Date retrieveTraialDate() throws ParseException, IOException
    {
          Date currentDate=new Date();
          System.out.println("Current Date $$$ "+currentDate);
          return currentDate;
    }

    public static void main(String args[]) throws ParseException, 
      IOException
    {
           Timer  timer=new Timer ();
           timer.schedule(new ITCBillDeskRetrieveTrialDDHHMMSS(),0,1000);

    }  
}

0 个答案:

没有答案