
Originally Posted by
leonidassavvides
exist any javascript function checks a date if is correct
eg a wrong date= 31 feb 2009, returns false ?
One does now.
When you set an out-of-bounds date, it will "roll over" to the best guess at what you meant.
Code:
function dateExists(date, month, year){
var d = new Date(year, month, date);
return d.getDate() === parseInt(date); //parseInt makes sure it's an integer.
}
//January 1, 2009
document.write(dateExists(1, 0, 2009) + '<br>'); //true
//February 31, 2009
document.write(dateExists(31, 1, 2009) + '<br>'); //false - rolls over to March 3, 2009; 3 !== 31

Originally Posted by
leonidassavvides
To show local time(NOW) GMT+2 to each visitor indepented where he is[time zone] I must use server time zone or exist and js function gives GMT TIME and after I add two hours to this ?
this is corect
var today2gmt = Date.UTC()+2*60*60;
// ms today GMT+2 TIME ANYWHERE
This builds an object: today2gmt = Date.UTC()+2*60*60 or not I must use
gmt2 - new Date(today2gmt); // this is corect ?
That's incorrect; Date.UTC requires at least two (three in IE) arguments (ECMA, Mozilla, Microsoft). But this works:
Code:
var d = new Date();
d.setHours(d.getUTCHours() + 2);
(Note that d.getUTCHours will be unreliable after this line, depending on the user's timezone.)

Originally Posted by
leonidassavvides
To asign to a day/month/year html form fields (date) the current date I must use if FormName="book" and day/month/year field names are "day","month","year" and I have a date object "gmt2"
document.book.day.value = gmt2.getDay();
document.book.month.value = months[gmt2.getMonth()]
document.book.year.value = gmt2.getFullYear();
when I must call these statements , when page loads at head section ?
This is a more reliable way:
Code:
document.forms.book.day.value = gmt2.getDay();
document.forms.book.month.value = months[gmt2.getMonth()]
document.forms.book.year.value = gmt2.getFullYear();
This must be done either here:
Code:
<body>
Put all your page's contents above the script tag.
<script type="text/javascript">//Move this script to its own file.
...
</script>
</body>
or here:
Code:
<head>
<script type="text/javascript">//Move this script to its own file.
window.onload = function(){
...
}
</script>
</head>
Bookmarks