i am trying to convert date to string in java.but i need coding for call date in javascript
<p>Here is my code: the code is for getting the value in server side, so i want to convert the date into string format then i call the data in script file</p>

<pre><code>**My Servlet code**


package pack.com;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class project extends HttpServlet {
    private String date_to_string;
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        Date dateNow = new Date();
        SimpleDateFormat formatDateJava = new SimpleDateFormat("MM/dd/yyyy");
        date_to_string = formatDateJava.format(dateNow);
        System.out.println("Today's date into MM/dd/yyyy format: " + date_to_string);
        StringBuilder sb = null;
        PrintWriter out = response.getWriter();
        sb = new StringBuilder();
        if (request.getParameter("today").equals("dateNow"))
        {
            sb.append("[");
            sb.append("{\"Stack_No\":\"13\",\"Buyer_Name\":\"Vickram\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"56\"},");
            sb.append("{\"Stack_No\":\"04\",\"Buyer_Name\":\"sivaji\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"45\"},");
            sb.append("{\"Stack_No\":\"25\",\"Buyer_Name\":\"mathavan\",\"No_of_Trips\":\"82\",\"Dispatched_Quantity\":\"34\"}");
            sb.append("]");
        } else if(request.getParameter("today").equals("dateNow-1")){
            sb.append("[");
            sb.append("{\"Stack_No\":\"06\",\"Buyer_Name\":\"karthik\",\"No_of_Trips\":\"28\",\"Dispatched_Quantity\":\"23\"},");
            sb.append("{\"Stack_No\":\"4\",\"Buyer_Name\":\"Murali\",\"No_of_Trips\":\"29\",\"Dispatched_Quantity\":\"8\"},");
            sb.append("{\"Stack_No\":\"6\",\"Buyer_Name\":\"MGR\",\"No_of_Trips\":\"10\",\"Dispatched_Quantity\":\"8\"}");
            sb.append("]");
        }else if(request.getParameter("today").equals("dateNow-2")){
            sb.append("[");
            sb.append("{\"Stack_No\":\"06\",\"Buyer_Name\":\"karthik\",\"No_of_Trips\":\"28\",\"Dispatched_Quantity\":\"23\"},");
            sb.append("{\"Stack_No\":\"4\",\"Buyer_Name\":\"Murali\",\"No_of_Trips\":\"29\",\"Dispatched_Quantity\":\"8\"},");
            sb.append("{\"Stack_No\":\"6\",\"Buyer_Name\":\"MGR\",\"No_of_Trips\":\"10\",\"Dispatched_Quantity\":\"8\"}");
            sb.append("]");

    }else if(request.getParameter("today").equals("dateNow-3")){
        sb.append("[");
        sb.append("{\"Stack_No\":\"13\",\"Buyer_Name\":\"Vickram\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"56\"},");
        sb.append("{\"Stack_No\":\"04\",\"Buyer_Name\":\"sivaji\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"45\"},");
        sb.append("{\"Stack_No\":\"25\",\"Buyer_Name\":\"mathavan\",\"No_of_Trips\":\"82\",\"Dispatched_Quantity\":\"34\"}");
        sb.append("]");
    }
    else if(request.getParameter("today").equals("dateNow-4")){
        sb.append("[");
        sb.append("{\"Stack_No\":\"13\",\"Buyer_Name\":\"Vickram\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"56\"},");
        sb.append("{\"Stack_No\":\"04\",\"Buyer_Name\":\"sivaji\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"45\"},");
        sb.append("{\"Stack_No\":\"25\",\"Buyer_Name\":\"mathavan\",\"No_of_Trips\":\"82\",\"Dispatched_Quantity\":\"34\"}");
        sb.append("]");
    }
    else if(request.getParameter("today").equals("dateNow-5")){
        sb.append("[");
        sb.append("{\"Stack_No\":\"13\",\"Buyer_Name\":\"Vickram\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"56\"},");
        sb.append("{\"Stack_No\":\"04\",\"Buyer_Name\":\"sivaji\",\"No_of_Trips\":\"34\",\"Dispatched_Quantity\":\"45\"},");
        sb.append("{\"Stack_No\":\"25\",\"Buyer_Name\":\"mathavan\",\"No_of_Trips\":\"82\",\"Dispatched_Quantity\":\"34\"}");
        sb.append("]");
    }
    else if(request.getParameter("today").equals("dateNow-6")){
        sb.append("[");
        sb.append("{\"Stack_No\":\"06\",\"Buyer_Name\":\"karthik\",\"No_of_Trips\":\"28\",\"Dispatched_Quantity\":\"23\"},");
        sb.append("{\"Stack_No\":\"4\",\"Buyer_Name\":\"Murali\",\"No_of_Trips\":\"29\",\"Dispatched_Quantity\":\"8\"},");
        sb.append("{\"Stack_No\":\"6\",\"Buyer_Name\":\"MGR\",\"No_of_Trips\":\"10\",\"Dispatched_Quantity\":\"8\"}");
        sb.append("]");

    }
        out.println(sb.toString());
        out.flush();
        out.close();
    }

}
</code></pre>

<p>Above the code is convert date to string but i am not sure is it correct.</p>

<p>html coding</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;

        &lt;!-- Always force latest IE rendering engine (even in intranet) &amp; Chrome Frame
        Remove this if you use the .htaccess --&gt;
        &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /&gt;

        &lt;title&gt;index&lt;/title&gt;
        &lt;meta name="description" content="" /&gt;
        &lt;meta name="author" content="nura" /&gt;

        &lt;!--&lt;meta name="viewport" content="width=device-width; initial-scale=1.0" /&gt; --&gt;
        &lt;!-- CSS --&gt;
        &lt;link rel="stylesheet" href="css/table.css" type="text/css" media="screen" title="no title" charset="utf-8"/&gt;
        &lt;!-- Replace favicon.ico &amp; apple-touch-icon.png in the root of your domain and delete these references --&gt;
        &lt;link rel="shortcut icon" href="/favicon.ico" /&gt;
        &lt;link rel="apple-touch-icon" href="/apple-touch-icon.png" /&gt;
        &lt;script type="text/javascript" charset="utf-8" src="js/jquery.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" charset="utf-8"&gt;
            $(document).ready(function() {
                $.ajax({
                type : "GET",
                url : yt_url,
                data : "servlet_id=1&amp;prop_id=" + propId,
                async : false,
                success : function(response) {
                    if (response.data) {
                    }
                }
            });

                    $("#j").text(json[0].Stack_No);
                    $("#i").text(json[0].Buyer_Name);
                    $("#h").text(json[0].No_of_Trips);
                    $("#m").text(json[0].Dispatched_Quantity);
                    $("#g").text(json[1].Stack_No);
                    $("#f").text(json[1].Buyer_Name);
                    $("#e").text(json[1].No_of_Trips);
                    $("#l").text(json[1].Dispatched_Quantity);
                    $("#c").text(json[2].Stack_No);
                    $("#b").text(json[2].Buyer_Name);
                    $("#a").text(json[2].No_of_Trips);
                    $("#k").text(json[2].Dispatched_Quantity);
                    $("#n").text(json[3].Stack_No);
                    $("#o").text(json[3].Buyer_Name);
                    $("#p").text(json[3].No_of_Trips);
                    $("#q").text(json[3].Dispatched_Quantity);
                    $("#r").text(json[4].Stack_No);
                    $("#s").text(json[4].Buyer_Name);
                    $("#t").text(json[4].No_of_Trips);
                    $("#u").text(json[4].Dispatched_Quantity);
                    $("#v").text(json[5].Stack_No);
                    $("#w").text(json[5].Buyer_Name);
                    $("#x").text(json[5].No_of_Trips);
                    $("#y").text(json[5].Dispatched_Quantity);
                });


        &lt;/script&gt;

    &lt;/head&gt;
    &lt;body&gt;
        &lt;img id="ajaxLoader" src="image/logo.jpg" style="display: none;" /&gt;

        &lt;div id="header"&gt;
            &lt;h2&gt;&lt;b&gt;Daily Despath Report&lt;/b&gt;&lt;/h2&gt;
        &lt;/div&gt;
        &lt;div id="container"&gt;
            &lt;h1&gt;Mine:-------&lt;h1&gt;
        &lt;/div&gt;
        &lt;body&gt;
            &lt;div id="time"&gt;
            &lt;span id=tick2&gt;
&lt;/span&gt;
&lt;script&gt;
function show2(){
if (!document.all&amp;&amp;
!document.getElementById)
return
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="PM"
if (hours&lt;12)
dn="AM"
if (hours&gt;12)
hours=hours-12
if (hours==0)
hours=12
if (minutes&lt;=9)
minutes="0"+minutes
if (seconds&lt;=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
thelement.innerHTML="&lt;b style='font-size:14;color:blue;'&gt;"+ctime
+"&lt;/b&gt;"
setTimeout("show2()",1000)
}
window.onload=show2
&lt;/script&gt;
&lt;div id="my"&gt;
&lt;script type="text/javascript" src="js/jquery-1.8.2.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var dateNow = new Date();
var month = dateNow.getMonth()+1;
var day = dateNow.getDate();
var year = dateNow.getFullYear();
var date = month + " /" + day + " /" + year;
function ShowSchedule() 
{
$('#today').val(date);
}
function ShowDay(temp,isNextDay)
{
if(isNextDay)
{
datecount=$('#'+temp).val();
if(datecount&gt;0){
var tempval=--datecount;
var cur_dat=new Date();
curdate=cur_dat.getDate();
var diff_dat=new Date();
diff_dat.setDate(curdate-tempval);
$('#today').val(diff_dat.getMonth()+1+" /"+diff_dat.getDate()+" /"+diff_dat.getFullYear());
$('#temp').val(tempval);
}

else{
alert("Data is available for up to today date only");
}
}
else{
datecount=$('#'+temp).val();
if(datecount&lt;=6){
var tempval=++datecount;
var cur_dat=new Date();
curdate=cur_dat.getDate();
var diff_dat=new Date();
diff_dat.setDate(curdate-tempval);
$('#today').val(diff_dat.getMonth()+1+" /"+diff_dat.getDate()+" /"+diff_dat.getFullYear());
$('#temp').val(tempval);
}else{
alert("Data is not available for more than 7 days from current date");
}
}
}
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;a id = "prev" href="#" onClick="ShowDay('temp',false)"&gt;Prev&lt;/a&gt;
&lt;input type="hidden" id="temp" value="0"&gt;
&lt;input type="text" id="today" size="10"&gt;
&lt;a id = "next" href="#" onClick="ShowDay('temp',true)"&gt;Next&lt;/a&gt; 
&lt;input type="hidden" id="temp" value="i"&gt;  
&lt;script&gt;ShowSchedule();
&lt;/script&gt;

&lt;/body&gt;

        &lt;div id="CSSTableGenerator" &gt;
            &lt;table &gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;i&gt;Materials&lt;/i&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;i&gt;Stack No&lt;/i&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;i&gt;Buyer Name&lt;/i&gt;&lt;/td&gt;
                    &lt;td &gt;&lt;i&gt;No of Trips&lt;/i&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;i&gt;Dispatched Quantity&lt;/i&gt;&lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                    &lt;td&gt;Screened Fines&lt;/td&gt;
                    &lt;td id="j"&gt;&lt;/td&gt;
                    &lt;td id="i"&gt;&lt;/td&gt;
                    &lt;td id="h"&gt;&lt;/td&gt;
                    &lt;td id="m"&gt;&lt;/td&gt;

                &lt;/tr&gt;

                &lt;tr&gt;
                    &lt;td&gt;Screened 5-18mm&lt;/td&gt;
                    &lt;td id="g"&gt;&lt;/td&gt;
                    &lt;td id="f"&gt;&lt;/td&gt;
                    &lt;td id="e"&gt;&lt;/td&gt;
                    &lt;td id="l"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Screened 10-30mm&lt;/td&gt;
                    &lt;td id="c"&gt;&lt;/td&gt;
                    &lt;td id="b"&gt;&lt;/td&gt;
                    &lt;td id="a"&gt;&lt;/td&gt;
                    &lt;td id="k"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Screened Lumps&lt;/td&gt;
                    &lt;td id="n"&gt;&lt;/td&gt;
                    &lt;td id="o"&gt;&lt;/td&gt;
                    &lt;td id="p"&gt;&lt;/td&gt;
                    &lt;td id="q"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Crushed Fines&lt;/td&gt;
                    &lt;td id="r"&gt;&lt;/td&gt;
                    &lt;td id="s"&gt;&lt;/td&gt;
                    &lt;td id="t"&gt;&lt;/td&gt;
                    &lt;td id="u"&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Crushed 5-18mm&lt;/td&gt;
                    &lt;td id="v"&gt;&lt;/td&gt;
                    &lt;td id="w"&gt;&lt;/td&gt;
                    &lt;td id="x"&gt;&lt;/td&gt;
                    &lt;td id="y"&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;

        &lt;/div&gt;
        &lt;div id="button"&gt;
            &lt;form&gt;
                &lt;br&gt;
                &lt;br&gt;
                &lt;b style="color:white"&gt;&lt;i&gt;Yesterday DDR&lt;/i&gt;&lt;/b&gt;
                &lt;br&gt;

                &lt;input type="button"
                style="
                background: -moz-linear-gradient(top,  rgb(255,183,107) 0%, rgb(255,167,61) 50%, rgb(255,124,0) 51%, rgb(255,127,4) 100%);
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(255,183,107)), color-stop(50%,rgb(255,167,61)), 
                color-stop(51%,rgb(255,124,0)), color-stop(100%,rgb(255,127,4)));
                background: -webkit-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: -o-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: -ms-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: linear-gradient(to bottom,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                "onClick="location.href='nura.html'" value='Click'&gt;
                &lt;a&gt;
                &lt;input type="button"
                style="
                background: -moz-linear-gradient(top,  rgb(255,183,107) 0%, rgb(255,167,61) 50%, rgb(255,124,0) 51%, rgb(255,127,4) 100%);
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(255,183,107)), color-stop(50%,rgb(255,167,61)), 
                color-stop(51%,rgb(255,124,0)), color-stop(100%,rgb(255,127,4)));
                background: -webkit-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: -o-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: -ms-linear-gradient(top,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                background: linear-gradient(to bottom,  rgb(255,183,107) 0%,rgb(255,167,61) 50%,rgb(255,124,0) 51%,rgb(255,127,4) 100%);
                "onclick="location.href='datepicker.html'" value='Trend'&gt;
                &lt;br&gt;
            &lt;/form&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
