-
I have the following code to get the current date, but on the output the date is appearing as '5 3 2001' which it obviously isn't. I've checked my computers date checkings, which are correct, so what am I doing wrong?
var today = new Date();
var now = today.getDate();
var theday = today.getDay();
var themonth = today.getMonth();
var theyear = today.getYear();
Response.Write (theday + " " + themonth + " " + theyear + " is the month<BR>")
Thanks in advance.
-
I have had this same problem at school. The clock was right, but when i did it in javascript it was an hour off. :confused:
-
did you find out what the problem was?
-
Dates in Javascript are a bit more involved than you think, try this:
Code:
<script language="JavaScript">
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.write(day + "/" + month + "/" + year);
</script>
-
looks familiar N*G*Evangelion ... :cool:
http://developer.irt.org/script/34.htm