Click to See Complete Forum and Search --> : new to javascript~ please help!


schmikes
11-03-2003, 02:07 AM
<html><head><title>Time 5</title>
</head><body><script language="javascript">
<!--
dt=new Date()
document.write("dt.getYear()<br>")
document.write("dt.getMonth()+1 <br>")
document.write("dt.getHours() <br>") //returns the hours of the Date object
document.write("dt.getDate() <br>") //returns the day of the month of the Date object
document.write("dt.getMinutes() <br>")
//-->
<body></body></html>


are there any problems? it just show nothing~
please help!
Thanks!

Gollum
11-03-2003, 02:25 AM
For one thing, you need to terminate the <script> tag - presumably just after the //--> bit

And secondly, I'm guessing that you want the values returned by dt.getYear(), etc and not the code. So you'll need to change all your statements to something like this...

document.write(dt.getYear() + "<br>");

Fang
11-03-2003, 02:46 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Basic HTML</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
<!--
var dt=new Date();
var str=dt.getYear();
//some browsers return years since 1900
if(str<1900) {
str+=1900;
}
str+="<br />";
str+=(dt.getMonth()+1)+"<br />";
str+=dt.getHours()+"<br />"; //returns the hours of the Date object
str+=dt.getDate()+"<br />"; //returns the day of the month of the Date object
str+=dt.getMinutes()+"<br />";
document.write(str);
//-->
</script>
</body>
</html>

Instead of getYear(), modern browsers support getFullYear() (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html#1193137)
See the tutorials (http://www.w3schools.com/default.asp) on (x)html, javascript and css.

schmikes
11-03-2003, 03:45 AM
oh icic~
Gollum and Fang, Thanks!