Updating Time

Updating Time

Posted in : Java Posted on : June 20, 2011 at 11:51 AM Comments : [ 0 ]

In this section we will discuss how can we update the time on the server

Updating Time

In this section we will discuss how can we update the time on the server.

The example is being given below will show you that how can you update the time. In example I used the addHeader() and setHeader() methods.

The setHeader() method sets the key/value in any request header.

The addHeader() method adds the user specified header.

Example : UpdatingTime.java

import java.text.DateFormat;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UpdatingTime extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) 
throws ServletException, IOException {
PrintWriter pw= res.getWriter();
res.addHeader("Language", "hi");

Locale locale = new Locale("hi", "");
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
res.setHeader("Refresh", "1");
pw.println("This page is refreshing in every 1 sec.");
pw.println(fmt.format(new Date()).toString());




Output : When you will this example the following output will look you. The time will refreshed in every 1 sec.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics