title: Converting String to Date in JavaScript
body: <p>In a JavaScript program, I have to get date in milliseconds or as a string in a format recognized by the parse method from user as input in textbox and then by clicking on a button convert it in <code>toString</code> and then clicking on second button getDate.</p>
  
  <p>I m confused how to correct or complete this code!</p>
  
  <p>my incomplete code is:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Demonstration of Date object - Javascript&lt;/title&gt;
    &lt;/head&gt;
    &lt;body topmargin="100px" leftmargin="130px"&gt;
      &lt;p&gt;
        &lt;font size="4" color="navy" face="candara"&gt;Demonstration of using the Date object in JavaScript. Enter a Date as a number in milliseconds, or as a string in format recognized by the parse method.&lt;/font&gt;
      &lt;/p&gt;
      &lt;form name="form1"&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;td&gt;Enter a Date:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="txt1"&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
        &lt;br&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="toString" onclick="tostring()"&gt;
              &lt;p id="demo1"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="getDate" onclick="getdate()"&gt;
              &lt;p id="demo2"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="getDay" onclick="getday()"&gt;
              &lt;p id="demo3"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="toDateString" onclick="datestring()"&gt;
              &lt;p id="demo4"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="getFullYear" onclick="getfullyear()"&gt;
              &lt;p id="demo5"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="getMonth" onclick="getmonth()"&gt;
              &lt;p id="demo6"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;input type="button" value="getTime" onclick="gettime()"&gt;
              &lt;p id="demo7"&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/form&gt;
      &lt;script type="text/javascript" language="javascript"&gt;
        function tostring() 
        {
        var d = new Date(document.form1.txt1.value);
        var n = d.toString();
        document.getElementById("demo1").innerHTML = n;
        }
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>