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 toString
and then clicking on second button getDate.
I m confused how to correct or complete this code!
my incomplete code is:
<html>
<head>
<title>Demonstration of Date object - Javascript</title>
</head>
<body topmargin="100px" leftmargin="130px">
<p>
<font size="4" color="navy" face="candara">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.</font>
</p>
<form name="form1">
<table>
<tr>
<td>Enter a Date:</td>
<td><input type="text" name="txt1"></td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<input type="button" value="toString" onclick="tostring()">
<p id="demo1">
</td>
</tr>
<tr>
<td>
<input type="button" value="getDate" onclick="getdate()">
<p id="demo2">
</td>
</tr>
<tr>
<td>
<input type="button" value="getDay" onclick="getday()">
<p id="demo3">
</td>
</tr>
<tr>
<td>
<input type="button" value="toDateString" onclick="datestring()">
<p id="demo4">
</td>
</tr>
<tr>
<td>
<input type="button" value="getFullYear" onclick="getfullyear()">
<p id="demo5">
</td>
</tr>
<tr>
<td>
<input type="button" value="getMonth" onclick="getmonth()">
<p id="demo6">
</td>
</tr>
<tr>
<td>
<input type="button" value="getTime" onclick="gettime()">
<p id="demo7">
</td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
function tostring()
{
var d = new Date(document.form1.txt1.value);
var n = d.toString();
document.getElementById("demo1").innerHTML = n;
}
</script>
</body>
</html>